[Solved] MainWindow example not restore layout of qdockwidgets which are added later



  • I'm trying to create a widget based app similar to MainWindow (QDockWidget) example. Take the example it self as an examle. It don't restore layout for QDockWidget which are added latter(QDockWidget wich are added after QMainWindow::show() method calls). What is the reason for that? Is that because widgets are added after QMainWinows is shown? or something else? How can I overcome this?



  • Do you mean that it does not restore layout after application restart?
    If so then you need to use "QSettings":http://qt-project.org/doc/qt-5/qsettings.html to save and restore a layout.



  • No, I'm talking about the example project comes with Qt. In that application you can add custom widgets at run-time and save it layout to a file, When I open that layout file it wont restore qdockwidgets which are added later.



  • Sorry for the trouble. I think I have changed ObjectName. Now it's working.



  • I guess you are talking about examples/widgets/mainwindows/mainwindow.

    It does restore the created and saved QDockWidget.
    But not immediately after you load layout.
    After you have loaded a layout you need to select "Add dock widget..." from "Dock Widgets" menu.
    Type the same name as you gave when you created that DockWidget and select "Restore" from "Location" drop-down bar.
    Click "Ok" and you will see it. :-)



  • Yes. The ObjectName is important.
    Glad that you resolved it.


Log in to reply
 

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