Important: Please read the Qt Code of Conduct -

How can I prevent QOpenGLWidget from stealing mouse press events from MainWindow?

  • Hello!

    This is probably something super simple but I just can't get anything to work!
    I have a QMainWindow and I need to trigger a function as soon as the user clicks to either move or resize the window. The same function will be triggered.

    But I just can't get the QMainWindow to register my event overrides.
    The events all end up in the QOpenGLWidget sub widget.

    I'm trying things like this on the OpenGL widget,


    but those didn't work.
    EDIT: Btw I'm on Linux.

    Does anyone know how to transfer mouse events back to my main window?


  • I'd start by subclassing it, and overriding the appropriate virtual event handlers, passing the event back to the parent. It's derived from QWidget, so that should work.

  • I have sub classes of both the main window and the gl widget but I'm realising that none of them register mouse clicks on the window borders.

    I think it's the X window manager that is absorbing those events and I can't figure out to get hold of them in Qt.

    EDIT: Ideally I'd probably be best of with some callback that can happen continously while window move or window scaling is happening.
    That works for me with the QStatusBar's QSizeGrip but that effect only happens there.
    It doesn't happen if I move or resize from the side borders or the top corners.
    I'm suspecting that's because X is handling the general window transforms but the StatusBar is handled by Qt.

  • Lifetime Qt Champion


    Might be a silly question but since it's related to resizing why not reimplement the resizeEvent method of your QMainWindow based class ?

  • @SGaist
    I have done that but it only triggers after the resize has happened while I need to trigger during resize is happening. I also need during window move is happeining.
    The same with moveEvent, it only triggers after the event and not during which I need.
    Or I can do my own little loop thing if I can get mouse down|up on the window borders, which I'm also unable to figure out how to get from Qt.

  • Lifetime Qt Champion

    Can you explain what you want to do during these events ?

  • I am doing some hardware video rendering on a Raspberry Pi and it does a custom draw straight over the screen.
    But I need to make it appear that it follows a Qt window that is being used by the main application. (someone else owns this project and I'm adding to it).
    So I need to take window transformation info as it happens on the fly, and modify the hardware drawing accordingly, so that it looks like it's 'attached' to the Qt window.

  • I'm having some luck just adding a X11 'XQueryPointer' to get the mouse button state and I think I can combine that with a eventFilter to allow me to do what I want.
    Now I'm just wondering if there's a 'tick' or refresh function that I can call for a QMainWindow. But that's a different question so Iv'e made a new query for that one.

Log in to reply