[SOLVED] After using QMainWindow restoreState QDockWidgets added don't end up in expected position

  • I've put together a QMainWindow with a number of QDockWidgets in the designer. The layout is saved using QSettings when the application closes and restored when the application launches after the QMainWindow is constructed.

    After this another QDockWidget is generated and added to the QMainWindow like this

    @QDockWidget *runtime_widget(new QDockWidget.......);
    addDockWidget(Qt::RightDockWidgetArea, runtime_widget);@

    In the designer I've placed a dock widget in the RightDockWidgetArea (let's call it designer_widget). The user moves designer_widget to the LeftDockWidgetArea then closes the application. The user re-opens the application and designer_widget appear on the left hand side, however, instead of showing up in the RightDockWidgetArea runtime_widget will show up tabbed along with designer_widget. Other dock widgets (created in the designer) show up wherever the user put them.

    What am I forgetting to do so that runtime_widget shows up on the right hand side of the main window?

  • Lifetime Qt Champion


    Can you show the store and restore related code ?

  • Saving

    @QSettings().setValue("WindowState", saveState());@



    the restore call happens before I add the widget that's showing up in the wrong place.

  • Lifetime Qt Champion

    Did you also do the same for the geometry ?

  • I wasn't, however, I just added that in but am getting the same behavior.

    @QSettings().setValue("WindowGeometry", saveGeometry());
    QSettings().setValue("WindowState", saveState());@


  • Lifetime Qt Champion

    Did you set a name on your dock widgets ?

  • This is embarrassing. Ends up there was some code elsewhere that was moving the new widget onto one of the designer widgets.

    I guess we can delete this thread if possible, sorry for taking up your time!

  • Lifetime Qt Champion

    Why delete it ? It can give a hint to another user experiencing the same problem as you.

    Just update the thread title prepending [solved] so other forum users may know a solution has been found :)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.