QGraphicsView with QGLWidget viewport renders child widgets incorrectly on Mac
-
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 1Testing 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 += svgWhy 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 -
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)
-
I will give that a try, thanks for the good suggestion.
Br.
Martin Havnør