Important: Please read the Qt Code of Conduct -

QDialog / QTabwidget bug

  • We have a QDialog thats completely designed with layouts.
    The main QVBoxLayout contains a QTabWidget that consists of several Widgets which are handled through layouts as well.

    The Problem now is that whenever we execute the dialog with a tab other than the first one, it is a bit smaller than that and resizes as soon as we change the tab to the first one.

    The weird thing is that it doesn't show this behaviour when I switch the tabs around, so that my original first tab is somewhere else in the order. Because now every tab opens in same size and changing tabs doesn't resize anymore.

    Does anyone know why this could happen?
    I suspect a bug in the way QTabWidgets calculate their size in regard to the content of the first widget, meaning it may ignore the first widget's layout at some point in the progress of exec() or show() or wherever it might be.

    Edit: I tried with several sizeconstraints and even with setfixedsize and I always get the same result.
    It wouldn't be a problem if I didn't need the tab to be first, but with those shenanigans I have to hack a solution.
    For example showing the first tab and quickly switching to the others would works. But thats ugly.
    I thought I fixed the problem once by iterating through all tabs with setCurrentIndex, but for some reason it doesn't work anymore.

  • I fixed it with a simpler hack:

    int MyDialog::exec()
    	QTimer::singleShot(0, [=]{ ui->tabWidget->setCurrentIndex(tab_index); });
    	return QDialog::exec();

    tab_index member was set beforehand.
    this works because basically my first tab is adjusted to size now but then we immediately switch to the other.

Log in to reply