Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Unable to restore layout changes in QDockWidgets
Forum Updated to NodeBB v4.3 + New Features

[solved] Unable to restore layout changes in QDockWidgets

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XavierLL
    wrote on last edited by XavierLL
    #1

    Hi,

    I am creating a MainWindow application, and when exiting the program I call

    void MyMainWindow::closeEvent(QCloseEvent *event)
    {
        QSettings settings("MyCompany", "MyApp");
        settings.setValue("geometry", saveGeometry());
        settings.setValue("windowState", saveState());
        QMainWindow::closeEvent(event);
    }
    

    As it is said in the documentation.

    An in the MainWindow constructor, after adding all the dockWidgets to the MainWindow I call readSettings() :

    void Imagine::readSettings()
    {
        QSettings settings;
        int number = settings.value("testNumberX").toInt();
        restoreGeometry(settings.value("geometry").toByteArray());
        if(!restoreState(settings.value("windowState").toByteArray()))
            qDebug() << "State not restored";
    }
    

    And this is the Constructor

    MyMainWindow::MyMainWindowQWidget *parent) 
    : QMainWindow(parent), _propertiesDock(nullptr), _sheetDock(nullptr), 
    _treeDock(nullptr)
    {
        ui.setupUi(this);
    
        setCentralWidget(0);
        setDockNestingEnabled(true); // For correct Docking without central widget
    
        _propertiesDock = new QDockWidget(this);
        _propertiesDock->setWindowTitle(QStringLiteral("Properties"));
        _propertiesDock->setWidget(new QWidget());
    
        _sheetDock = new QDockWidget(this);
        _sheetDock->setWindowTitle(QStringLiteral("Sheet"));
        _sheetDock->setWidget(new QWidget());
    
        _treeDock= new QDockWidget(this);
        _treeDock->setWindowTitle(QStringLiteral("Objects"));
        _treeDock->setWidget(new QWidget());
    
        setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North);
        setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North);
       setTabPosition(Qt::BottomDockWidgetArea, QTabWidget::North);
       setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
    
       addDockWidget(Qt::TopDockWidgetArea, _treeDock);
       addDockWidget(Qt::TopDockWidgetArea, _sheetDock);
       addDockWidget(Qt::TopDockWidgetArea, _propertiesDock);
    
       readSettings();
    }
    

    The testNumberX is recovered Ok, and also the geometry, but not the state of the dockWidgets. So if I change a dockWidget from the rightArea to the leftArea, when I restart the application the changes have not been saved.

    Is it possible to change the state of the dockWidgets in an easy way?

    thanks!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Hi, welcome to devnet.

      saveState() uses objects names. You are not giving your dock widgets names so they can't be identified. Use setObjectName() on the docs (and toolbars too if you have any movable) before saving/restoring.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        XavierLL
        wrote on last edited by
        #3

        Thanks Chris, that solved the problem :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved