Hmm, I tried the suggestion now and it also does not work.
I removed all new/delete and hide() on the status bar for testing, but it still calculates the wrong size after the first construction of the widgets.
In the constructor of my main window, I only set up the layout and central widget, but not the widgets inside the central widget, because they depend on user choice (only one option is ever called per main window). I have something like
MainWindow::MainWindow() :
{
// connect slots / configure layout ..
// there is no show() here
}
MainWindow::open(bool use_scroll) { // this is called from outside MainWindow
// ..
if(!m_initialized) use_scroll ? init_with_scroll() : init_without_scroll();
// line A
load_content(); // this loads e.g. the pixmap in the label in the with_scroll case
// line B
}
MainWindow::init_with_scroll() {
// init widgets / add to layouts / connect slots
// line C
show();
// line D
}
std::cout << "height " << statusBar()->height() << std::endl;
}
// same procedure for init_without_scroll() ...
MainWindow::MainWindow() :
QMainWindow { }, // .. init central widget & layout
{
// connect slots / configure layout ..
// there is no show() here
}
MainWindow::open(bool use_scroll) { // this is called from outside MainWindow
// ..
if(!m_initialized) use_scroll ? init_with_scroll() : init_without_scroll();
// line A
load_content(); // this loads e.g. the pixmap in the label in the with_scroll case
// line B
}
MainWindow::init_with_scroll() {
// init widgets / add to layouts / connect slots
// line C
show();
// line D
}
MainWindow::showEvent(QShowEvent*) {
std::cout << "height " << statusBar()->height() << std::endl;
}
// same procedure for init_without_scroll() ...
To copy to clipboard, switch view to plain text mode
I tried moving statusBar() between the lines A-D, but first thing I noticed is that in the init_without_scroll() case, the status bar size is always calculated correctly (nvm the grey text, I had a different output in the resize function - the output in showEvent does not differ in the two cases. Though somehow I get the correct value in my resize function in this case, not sure why ..). On the other hand, in the init_with_scroll() case, the status bar height gives different, but always wrong results:
- above code unchanged (first statusBar() inside showEvent): "height 30"
- statusBar() or statusBar()->show() on line C: "height 18"
- statusBar() or statusBar()->show() on line A, B, D: "height 30"
Getting different sizes before and after show() makes sense, but why is it always wrong? I tried to reduce the code to everything I think is relevant, but I guess it looks like there might be an issue somewhere else and I should try to compile a MWE. But for now I guess I will just set the size manually and hope it doesn't change ..
Bookmarks