Problem adding QGLWidget to QGridLayout
Marga last edited by
I have a QGridLayout set up, where I insert my widgets. I have 3 widgets: QSplitter (dirBrowser), a QTextEdit (textView) and a QGLWidget (windowOpenGL). My code is the following:
[CODE]void setupUi(QMainWindow *mainWindow)
gridLayout = new QGridLayout();
layoutWidget = new QWidget(mainWindow);
windowOpenGL = new GLWidget(mainWindow);
dirBrowser = new QSplitter(mainWindow); //define the where the browsers will be contained
//... here I add QListViews and QTreeViews to the splitter
textView = new QTextEdit(mainWindow);
gridLayout->addWidget(dirBrowser, 0, 0, 1, 1); gridLayout->addWidget(textView, 1, 0, 1, 1); gridLayout->addWidget(windowOpenGL, 2, 0, 1, 1);
// .. here there are some connects(...)
Using this code as it is, the window does not display the OpenGL window. However, if I don't add the QTextEdit to the grid layout, it displays normally. The strange thing is that if instead of adding QTextEdit to the grid I add, for a example, a simple button, the OpenGL widget is displayed correctly as well.
What am I missing??? I would appreciate SO MUCH your help!!
Thanks in advance!
Cannot see anything obviously wrong with that code.
Except maybe that you are passing the mainWindow as parent to widgets that will have the layoutWidget as parent. Since you are putting all the widgets in layouts you don't really have to pass a parent argument to the constructors at all, so I would remove that.
Another option would be to try a QVBoxLayout instead.
Since you seem to be using only one column, a QVBoxLayout should do the same thing (and could work better, if you are lucky).
And one more thing I just remembered - are you sure the OpenGL window is not there, maybe it's just very small - I think the default size may be very small, possibly even with zero width and height.
Marga last edited by
Thanks a lot!! Your reply was really useful. I realised later that I was passing the wrong parent to the widgets, but now I will follow your advice of simply not passing anything at all :)
I discarded the possibility of the size of the widget being 0 because the problem persisted after setting a fixed size to the QTextEdit widget. BUT after playing around with other functions it turns out you are right! If I set a minimum size to the OpenGL widget, I can see it on the screen! I am new to Qt and didn't know widgets could have size 0 and not be shown on the screen. Now that I know the solution it looks so obvious :P
Thanks a million for taking the time to reply, I really appreciate it!
No problem, just happy to be able to help out!