summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-06-16 13:16:58 +0200
committerIvan Solovev <ivan.solovev@qt.io>2022-06-17 20:59:21 +0200
commit2ed54dedf3783471716b21509db1f8279d5b5af8 (patch)
tree7d5e4aff56764f9055a5cbb2c2a55e7b0034577c /src/widgets/widgets
parentb2fb14b7ba1db35eebf7621ead12909b35ec4042 (diff)
QMainWindow: fix restoreState() for toolbars
Restoring the toolbar state of a QMainWindow could not update QWidgetPrivate::widgetItem for the QToolBar, because at that point it was still holding the pointer to the widgetItem of the previous state. Later on, when the new state was successfully applied, the previous state was deleted, and the corresponding widgetItem was reset to nullptr. This patch explicitly resets the QToolBar's widgetItem while updating the state, so that it is later correctly updated while creating a new QWidgetItemV2. Fixes: QTBUG-102395 Pick-to: 6.4 6.3 6.2 5.15 Change-Id: I17613d62423edcc0faf85ecb0a714865a50d87e8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qtoolbararealayout.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp
index 09929e7234..adddfbc529 100644
--- a/src/widgets/widgets/qtoolbararealayout.cpp
+++ b/src/widgets/widgets/qtoolbararealayout.cpp
@@ -1328,6 +1328,10 @@ bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*
}
if (applyingLayout) {
+ // Clear the previous widgetItem for the toolBar, so that it's
+ // assigned correctly in QWidgetItemV2 constructor.
+ auto *toolBarPrivate = QWidgetPrivate::get(toolBar);
+ toolBarPrivate->widgetItem = nullptr;
item.widgetItem = new QWidgetItemV2(toolBar);
toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
toolBar->setVisible(shown & 1);