View Full Version : QMainWindow and its QDockWidget

13th January 2006, 18:30
Hi everybody,
I have a simple QMainWindow with a QDockWidget (a tool box) and a central widget (see the joined file called MainWindow1.jpg I don't know how to insert them directly in the text).
When I click on one button of the tool box, I need to change the central widget of the main window :

QPushButton *quit = new QPushButton(tr("&Quit"));
quit->setFont(QFont("Times", 18, QFont::Bold));
quit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);

delete centralWidget();


But the problem is that the dock widget (the tool box) now takes a half of the main window horizontaly !!!! (see MainWindow2.jpg) :confused:

To avoid the resizing of the dock widget I wrote the following code:


The result was not what I expected : the dock widget is correctly resized but there is a kind of frame taking a half of the main window !!!! (see MainWindow3.jpg)

Somebody have an idea?

13th January 2006, 19:33
The docs say:
void QMainWindow::setCentralWidget ( QWidget * widget )
Sets the given widget to be the main window's central widget.
Warning: This function should be called at most once for each main window instance

Maybe you should use QStackedWidget as a central widget?

13th January 2006, 21:42
Thanks for your advice. It's true that the behaviour was not very nice.