0

I am subclassing QOpenGLWindow (not QGLWidget or QOpenGLWidget) and calling

auto container = QWidget::createWindowContainer(my_opengl_window);

to place it in the layout of a parent QWidget.

The window displays correctly and I can interact with it, but container (and its parent widget) do not receive context menu events when I right-click within my_opengl_window. I do get a context menu if I right-click on the slim margin between the window and its container.

void MyGLWindow::mousePressEvent (QMouseEvent * e)
{
    qDebug (__PRETTY_FUNCTION__);

    QOpenGLWindow::mousePressEvent (e);
}

The above shows me that my_opengl_window is receiving mouse clicks. I have also tried e->ignore () but still the parent does not receive a context menu event.

Also, setCursor and setToolTip on the container widget have no effect. I suspect this may be related.

How can I get these mouse events to work on a QOpenGLWindow container?

spraff
  • 32,570
  • 22
  • 121
  • 229
  • How are you checking for context menu events in the `QOpenGLWindow`? As far as I know `QOpenGLWindow` just doesn't generate/handle `QContextMenuEvent` at all. – G.M. Feb 04 '20 at 17:56
  • As far as ***I*** know, `QOpenGLWindow` just doesn't generate/handle `QContextMenuEvent` at all, but I can't see that this is documented. – spraff Feb 05 '20 at 13:51
  • Sorry but I really don't understand that last comment. Why would they document functionality that *isn't* there? `QWidget` has the [`QWidget::contextMenuEvent`](https://doc.qt.io/qt-5/qwidget.html#contextMenuEvent) member, `QOpenGLWindow` doesn't. I think it's simply the case that you have to create/show the menu yourself on a right mouse button press or click. – G.M. Feb 05 '20 at 14:07
  • Because I want the *containing* `QWidget` to have a context menu event, *like normal*. Clicks are still being detected on the widget, but the context menu event is somehow being suppressed and I can't see a reason why. – spraff Feb 05 '20 at 14:39

0 Answers0