Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Using QGLWidget as Viewport for QGraphicsView creates problems for dock widgets?
I am attempting to use a QGraphicsView as the central widget for a QMainWindow-based application.
I would like Qt to use OpenGL for rendering the QGraphicsScene that is attached to the QGraphicsView.
The setup works fine as long as the QGraphicsView is the only widget attached to the QMainWindow. However, when I also have a QDockWidget attached, Qt fails to redraw the dock when it is moved and complains with the error:
"QGLContext::makeCurrent() : GetDC() failed: Invalid window handle."
a) A custom class called "GraphWidget" inherits from QGraphicsView and includes the following in its constructor:
graphScene_ = new QGraphicsScene();
glWidget_ = new QGLWidget(QGLFormat(QGL::SampleBuffers));
b) The constructor for my "MainWindow" class which inherits from QMainWindow includes the following:
centralGraphWidget_ = new GraphWidget();
dock_ = new QDockWidget(tr("App Widget"), this);
dockContentWidget_ = new QListWidget();
Simply commenting out the setViewport(glWidget_); line solves the problem...but also stops using OpenGL to render the scene.
Thanks for any help!
Edit: please use @ tags around code sections; Andre
baysmith last edited by
Have you tried setting a generic QWidget as the central widget and making the GraphWidget a child of it?
Thanks Bradley--I do see that there are complaints of trying to use QGraphicsView as the central widget for a QMainWindow.
Unfortunately, if I modify the constructor for the MainWindow as you suggest:
@centralWidget_ = new QWidget(this);
centralGraphWidget_ = new GraphWidget(centralWidget_);
QGridLayout *layout = new QGridLayout;
[...same dock setup as before...]@
I see no change in the behavior, and still get the failure to redraw the dock as well as the GLContext error.
Edit: again, please use @ tags around code sections; Andre
I wanted to post again in this section just to close out the issue. It appears to be a problem with Qt 4.7.0. When I rebuild the same project with 4.7.4, the problem disappears.
I did not investigate further to identify more precisely where things went wrong.
mazzzterz last edited by
Looks like this problem is a lot like mine. I'm using Ubuntu 12.04 with Qt 4.8.1. I'm witnesing some bizzare stuff. I have a QGLWidget that i can see some graphic in orthographic and perspective view. Orthographic is OK, but Perspective doesn't work anymore... just an empty scene with nothing in it.
Here is the problem with a story... I had a course project that used to work ok, but two months later I had to do some modifications to it and... it didn't work anymore. I was looking through the code and wondered and wondered what have I done wrong... I had a few older version that I new they worked, but... they didn't anymore, except for the oldest one... Reverting the newest one to the oldest one I found where the problem was. If I removed the QListWidget from the ui, then my perspective view works, if I add it again, then it stops to work. Here is something even more bizzare... if I move the QListWidget up or down from the QListWidget then it works... if it's on the same level... it doesn't(doesn't matter whether it's left or right).
It's hard for me to even imagine how this happen and what does position in the window of some widget does to perspective view of QGLWidget...