Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Poor QOpenGLWidget performance on OS X, QOpenGLWindow question
QtWS25 Last Chance

Poor QOpenGLWidget performance on OS X, QOpenGLWindow question

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew S.
    wrote on last edited by Andrew S.
    #1

    Hi!

    I have a problem in QOpenGLWidget performance on OS X (MacBook Pro Late 2013 Retina). As I understand QOpenGLWidget have to do full window composition before displaying its content. I have tried using QOpenGLWindow and it works MUCH faster on Mac & Windows. I need to use it embedded inside regular QWidget UI. But its not clear how to forward QOpenGLWindow's events to parent underlaying widget. Underlaying widget actions also aren't working because QOpenGLWindow stealing focus, and there's no way to add an action directly to QOpenGLWindow. Is it possible to use QOpenGLWindow just for displaying content, and make it transparent for all input events? Qt::WindowTransparentForInput flag didn't help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      From your description, you might be experiencing something similar to that bug . Is this the case ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Andrew S.
        wrote on last edited by Andrew S.
        #3

        Hi!

        The bug says about top level windows, also the window there is translucent, but my window is embedded using QWidget::createWindowContainer (not a top level window) and must be completely opaque for performance reason. I have checkout Windows code and find out that WindowTransparentForInput works only for top level windows:

        https://github.com/qtproject/qtbase/blob/5bfac9d653357c906946563b9494d7ae69cdad92/src/plugins/platforms/windows/qwindowswindow.cpp#L539

        With WS_EX_TRANSPARENT flag it also use WS_EX_LAYERED which will decrease performance.

        UPDATE: I tried to use Win32 API call to enable WS_EX_TRANSPARENT - unfortunately underlaying widget still not getting events.

        Andrew.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you could install an event filter on it and ignore everything keyboard/mouse related.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Andrew S.
            wrote on last edited by
            #5

            This doesn't work too, event just goes nowhere. I'm thinking about posting the event back to the QMainWindow by QApplication::sendEvent.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              How did you setup the event filter ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                How did you setup the event filter ?

                A Offline
                A Offline
                Andrew S.
                wrote on last edited by Andrew S.
                #7

                @SGaist

                I have minized the code. When I click on the left green side (QOpenGLWindow) I get this error on Windows in app's output and also don't get any events from mouse (mousePressEvent, contextMenuEvent, wheelEvent, ...):

                requestActivate() called for QOpenGLWindow(0x8f8400f450) which has Qt::WindowDoesNotAcceptFocus set.

                On OSX everything seems work fine. Don't know how this works on Linux. Using Qt 5.5.0 open source.

                
                #include <QApplication>
                #include <QOpenGLWindow>
                #include <QOpenGLFunctions>
                #include <QAction>
                #include <QDebug>
                
                class OpenGLWindow : public QOpenGLWindow, protected QOpenGLFunctions
                {
                    Q_OBJECT
                
                public:
                
                    OpenGLWindow()
                    {
                        setFlags(flags() | Qt::WindowDoesNotAcceptFocus | Qt::WindowTransparentForInput);
                    }
                
                    void initializeGL()
                    {
                        initializeOpenGLFunctions();
                    }
                
                    void paintGL()
                    {
                        glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
                        glClear(GL_COLOR_BUFFER_BIT);
                    }
                
                };
                
                class MainWidget : public QWidget
                {
                    Q_OBJECT
                
                    OpenGLWindow *openGLWindow;
                
                public:
                
                    MainWidget() :
                        openGLWindow(new OpenGLWindow())
                    {
                        QWidget *widget = QWidget::createWindowContainer(openGLWindow, this);
                        // widget->setAttribute(Qt::WA_TransparentForMouseEvents);
                
                        widget->setFixedSize(200, 300);
                
                        setFocusPolicy(Qt::StrongFocus);
                
                        setFixedSize(400, 300);
                
                        QAction *action = new QAction(tr("Some Action"), this);
                        action->setShortcut(QKeySequence(Qt::Key_A));
                        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
                        addAction(action);
                        connect(action, SIGNAL(triggered()), this, SLOT(onAction()));
                    }
                
                    void contextMenuEvent(QContextMenuEvent *e)
                    {
                        qDebug() << "Context menu event";
                
                        QWidget::contextMenuEvent(e);
                    }
                
                    void wheelEvent(QWheelEvent *e)
                    {
                        qDebug() << "Mouse wheel event";
                
                        QWidget::wheelEvent(e);
                    }
                
                    void mousePressEvent(QMouseEvent *e)
                    {
                		qDebug() << "Mouse press event";
                
                        QWidget::mousePressEvent(e);
                    }
                
                    void keyPressEvent(QKeyEvent *e)
                    {
                        qDebug() << "Key press event";
                
                		QWidget::keyPressEvent(e);
                    }
                
                private slots:
                
                    void onAction()
                    {
                		qDebug() << "Action event";
                    }
                };
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                
                    MainWidget w;
                    w.show();
                
                    return a.exec();
                }
                
                // Avoid linker error
                #include "main.moc"
                

                Also please create empty main_p.h to avoid linker error.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  What setup do you have on Windows ? MultiScreen ? Graphic card ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    What setup do you have on Windows ? MultiScreen ? Graphic card ?

                    A Offline
                    A Offline
                    Andrew S.
                    wrote on last edited by Andrew S.
                    #9

                    @SGaist

                    Windows 8.1, NVIDIA GeForce 660M, single display.

                    The problem is about routing of events, not graphics actually.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Indeed, but having a multiple-screen setup might also influence things a bit.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved