PDA

View Full Version : Child Widgets In MainWindow



RY
3rd October 2008, 19:03
I have created a custom MainWindow from QMainWindow and a custom widget from QGraphicsView. I'm trying to use a QGridLayout in MainWindow and place my custom widget in it. However, when I use the following in the MainWindow constructor:

Layout = new QGridLayout();
Layout->addWidget(CktArea);
setLayout(Layout);

The widget does not seem to appear anywhere.

If I also include at the botton of the previous code:

CktArea->show();

The widget shows up, but in another window that has a different menu bar than the MainWindow. Also, if I wanted to hide a widget, how would that work as well?

Thank you!

spirit
3rd October 2008, 19:55
you need to create a widget then place on this widget your QGridLayout and the set this widget as centarl widget for QMainWindow.

RY
4th October 2008, 06:18
That seems so round about. Just curious, why does it have to be done that way? :P

spirit
4th October 2008, 08:39
it's not a work-around. at first all layouts in Qt are not widgets, but they keep track of resizing them. QMainWindow also has own layout binder for toolbar, dockwidget etc. so, when you create a widget(A) or a dialog you must put a layout on it for enabling it to properly resize the widget(A) and widgets in the layout. the same situation in QMainWindow, but as for the widget(A) it is a central widget which you must add to QMainWindow.