Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-32639

QGraphicsView with QGLWidget viewport renders child widgets incorrectly

    XMLWordPrintable

Details

    • macOS

    Description

      As the title suggests I am having child widgets of a QGraphicsView rendered incorrectly on Mac if its viewport is a QGLWidget. Additionally multiple error messages are dumped to the console:

      Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt4467 <Error>: CGContextSetShouldAntialias: invalid context 0×0
      Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt4467 <Error>: CGContextSetShouldSmoothFonts: invalid context 0×0
      Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt4467 <Error>: CGContextSetFillColorSpace: invalid context 0×0
      Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt4467 <Error>: CGContextSetFillColor: invalid context 0×0
      QMacCGContext:: Unsupported painter devtype type 1
      QMacCGContext:: Unsupported painter devtype type 1
      QMacCGContext:: Unsupported painter devtype type 1

      Testing the code on Windows and Linux does not cause the error messages, but there are slight deviations in how child widgets are rendered.

      Here’s the strange part: setting the window opacity of the child widget to anything but its default value 1.0 fixes the problem. Ie.uncomment the setWindowOpacity(0.99); line and the bug is gone. However this seriously impairs performance on more advanced scenes than the one described below.

      This bug may be related to https://bugreports.qt-project.org/browse/QTBUG-20445.

      Code that reproduces the problem:

      main.cpp
      #include <QApplication>
      
      #include <QtWidgets>
      #include <QGLFormat>
      
      int main(int argc, char *argv[]) {
      QApplication app(argc, argv);
      
      // Create a graphics scene
      QGraphicsScene scene;
      
      // Create a graphics view for the scene
      QGraphicsView view(&scene);
      
      // Define a GLWidget viewport for the graphics view
      view.setViewport(new QGLWidget());
      
      // Create an overlay with a layout containing more widgets
      QGroupBox *groupBox = new QGroupBox("Contact Details");
      QFormLayout *layout = new QFormLayout;
      layout->addRow(new QLabel("Telephone number"), new QLineEdit());
      groupBox->setLayout(layout);
      
      // Add the overlay to the graphics scene
      QGraphicsProxyWidget *proxy = scene.addWidget(groupBox);
      
      // By setting the overlay as semi-transparent the app works. It severely slows down an application with performance requirements.
      // Why is this needed? Can it be avoided?
      // groupBox->setWindowOpacity(0.99);
      
      // Give the graphics view a size and show it
      view.resize(800, 800);
      view.show();
      
      return app.exec();
      }
      

      The code is taken from the Qt 5.0 documentation – simply changing its QGraphicsView viewport to a QGLWidget.

      The example main() from above was run in a larger project with the following modules added to the .pro file should that have any effect:
      QT += opengl
      QT += network
      QT += sql
      QT += webkitwidgets
      QT += svg

      It is also worth noting that other artefacts are observed in the larger project, including color from subwidgets "leaking onto" triangles drawn using GL11 code in QGraphicsScene::drawBackground(..). These artefacts vary between platform, but are present on both Linux, Windows and Mac. All of this is negated once the setWindowOpacity(0.99) hack is in place, but the performance hit is massive.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              rodskjegg Martin Havnør
              Votes:
              8 Vote for this issue
              Watchers:
              17 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes