Results 1 to 2 of 2

Thread: Problems with clipping and vsync of OpenGL widget container

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Problems with clipping and vsync of OpenGL widget container

    Hi all,

    after updating my application from Qt 4.8 to Qt 5.4 I was facing problems with my QGLWidget. I got some strange white rectangles and painting problems on OS X (it is a multi-platform application and there were no problems on Windows). Since QGLWidget is deprecated I decided to change my implementation. Unfortunately I can't use the newly introduced QOpenGLWidget since I need full control over the buffer swap and rendering into an FBO is not an option right now. After reading some threads I finally chose to implement it the way it is explained in the OpenGL Window Example of Qt 5.4 (http://doc.qt.io/qt-5/qtgui-openglwindow-example.html). In short, QWindow with OpenGL surface and a QOpenGLContext. For getting a widget out of the window I am using QWidget::createWindowContainer. Everything works pretty good except two problems:
    1. My OpenGL widget can have a fixed size. It is child of a layouting widget which is the central widget of my main window. The OpenGL widget is always put in the center of the layouting widget. I also have dock widgets to the left and right as well as toolbars. Now when resizing the the main window it can happen that the size of the central widget is smaller than the fixed size of my OpenGL render widget. In that case it is moved outside of the central widget area and should be covered by the toolbars and the dock widgets. But this is unfortunately not happening. It is always drawn on top of everything. This scenario was working with the old and now deprecated QGLWidget. I attached some screenshot which show the problem.
      Screen Shot 2015-05-06 at 14.45.59.jpg Screen Shot 2015-05-06 at 14.46.30.png Screen Shot 2015-05-06 at 14.46.41.png
    2. The second problem is related to vsync. On my Mac it seems to work if I set the swap interval to zero in the surface format. However I am still limited to 60 fps which reflects my monitor refresh rate. With the QGLWidget I am getting around 200 fps with the same test scene. Is there anything else I need to take care of? However, on my Windows machine setting the swap interval to zero does not seem to have any impact at all. Vsync is always on.


    Any help is highly appreciated. If necessary I can post the source code of my demo scene.

    Thanks,
    Marcus

  2. #2
    Join Date
    Aug 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with clipping and vsync of OpenGL widget container

    UPDATE: Ok, I figured out that the use of QWidget::createWindowContainer has limitations regarding stacking order. I found a possible solution where the widget is inserted in a QMdiArea. This solved the clipping problem for Windows. Unfortunately on OS X I am now getting the the same problem as with QGLWidget. On application startup a white rectangle is drawn at the top left corner of my main window. After some research it found the cause for it: It is a hidden toolbar with a widget in it. If I do not hide the the toolbar (in my code), the white rectangle is gone. Also when I show the toolbar in my application, the white rectangle goes away and won't appear again. Another remark, my QGLWidget is child of a parent widget which again is the central widget of my application. If I directly use the QGLWidget as the central widget, the problem also does not occur.

    To sum it up:
    • I have a QGLWidget with a parent QWidget as the central widget of my application.
    • I have a hidden tool bar with a widget in it.
    • When I start the application on OS X, a white rectangle appears at the top left corner of my application.
    • The rectangle goes away after showing the toolbar.
    • The problem does not occur if I do not hide the toolbar in my code or if I use the QGLWidget directly as the central widget.


    Here is some simple demo code which shows the problem:
    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QGLWidget>
    4. #include <QToolBar>
    5. #include <QMenuBar>
    6. #include <QMenu>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. //QCoreApplication::addLibraryPath("Qt/plugins");
    11.  
    12. QApplication app(argc, argv);
    13.  
    14.  
    15. main.setStyleSheet("background-color: black;");
    16.  
    17. QWidget *central = new QWidget(&main);
    18. QGLWidget *gl = new QGLWidget(central);
    19. main.setCentralWidget(central);
    20.  
    21. QWidget *w = new QWidget();
    22. QToolBar *tb = new QToolBar("Test");
    23. tb->addWidget(w);
    24. tb->hide();
    25.  
    26. main.addToolBar(Qt::BottomToolBarArea, tb);
    27.  
    28. QMenu *m = main.menuBar()->addMenu("View");
    29. m->addAction(tb->toggleViewAction());
    30.  
    31. main.show();
    32.  
    33. main.resize(800, 600);
    34.  
    35. return app.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 

    Unfortunately I can't upload an image of the problem because I currently always getting an error while trying to upload the file.

    To me this looks like a bug in Qt or am I doing something wrong?

    Thank,
    Marcus
    Last edited by dropkickz; 11th May 2015 at 13:22.

Similar Threads

  1. transparent widget container
    By sajis997 in forum Newbie
    Replies: 3
    Last Post: 3rd November 2014, 18:23
  2. Replies: 1
    Last Post: 23rd June 2011, 23:09
  3. QGraphicsView + opengl + Vsync
    By medved6 in forum Qt Programming
    Replies: 3
    Last Post: 11th March 2011, 16:20
  4. Container widget with scrollbars
    By a550ee in forum Qt Programming
    Replies: 7
    Last Post: 15th July 2008, 10:44
  5. QCanvas clipping problems
    By ksierens in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2007, 16:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.