
Originally Posted by
spraff
If I resize the main window, the centralWidget is smaller than that size becuase
the toolbar takes up room. Ideally the resize method would set the centralWidget's size and grow the QMainWindow to fit the toolbars. (If I call resize on the centralWidget, the QMainWindow doesn't seem to respond.)
Basically you have two choices.
1. Let QMainWindow adjust its size according to its contents using resize(sizeHint()) and adjust layouts so that you are satisfied with the size hint
2. Use resize(sizeHint()+QSize(addWidth, addHeight)) where addWidth and addHeight are the values which you want to add to the size hint (which you have to calculate manually).
There is also a third, a bit wacky solution - go even further and ask Qt to calculate the offset for you.
QSize margins
= size
()-centralWidget
->size
();
// this is the size of "stuff" around the central widget QSize myDestSize
= ...;
// set to whatever you want the central widget to be resize(myDestSize+margins);
QSize margins = size()-centralWidget->size(); // this is the size of "stuff" around the central widget
QSize myDestSize = ...; // set to whatever you want the central widget to be
resize(myDestSize+margins);
To copy to clipboard, switch view to plain text mode
Another acceptable solution would be to create the QToolBar to be initially floating, but I can't see how.
Probably like this:
addToolBar(Qt::NoToolBarArea, thing);
addToolBar(Qt::NoToolBarArea, thing);
To copy to clipboard, switch view to plain text mode
Bookmarks