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. QGraphicsView with QGLWidget viewport renders child widgets incorrectly on Mac

QGraphicsView with QGLWidget viewport renders child widgets incorrectly on Mac

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rodskjegg
    wrote on last edited by
    #1

    Hi,

    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 OSMViewerQt[4467] <Error>: CGContextSetShouldAntialias: invalid context 0x0
    Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt[4467] <Error>: CGContextSetShouldSmoothFonts: invalid context 0x0
    Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt[4467] <Error>: CGContextSetFillColorSpace: invalid context 0x0
    Jul 24 15:54:51 Martin-Havnrs-MacBook-Pro.local OSMViewerQt[4467] <Error>: CGContextSetFillColor: invalid context 0x0
    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.

    Code that reproduces the problem:
    @

    #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(400, 400);
    view.show();
    
    return app.exec();
    

    }
    @

    The code is taken from the "Qt 5.0 documentation":http://qt-project.org/doc/qt-5.0/qtwidgets/qgraphicsproxywidget.html - 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

    Why do I see deviations in how widgets are rendered with the QGLWidget viewport?
    Where does the nil-context attempted used somewhere in rendering come from?
    Why does adding window opacity seemingly fix the issue?
    What can I do to avoid these problems without the window opacity hack?

    Br.
    Martin Havnør

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

      Hi and welcome to devnet,

      Sounds like a bug to me, did you try to look at the "bug report system":https://bugreports.qt-project.org/issues/ to see if someone already reported this ?

      If not you might consider open a bug report with all the information you provided in this post.

      Maybe asking on the interest mailing list (this is where you'll find Qt's developer/maintainer, this forum is more user oriented)

      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
      • R Offline
        R Offline
        Rodskjegg
        wrote on last edited by
        #3

        I will give that a try, thanks for the good suggestion.

        Br.
        Martin Havnør

        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