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. QDockWidget and saveState()
Qt 6.11 is out! See what's new in the release blog

QDockWidget and saveState()

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 12.2k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I can see that it is saving the state of the dock by looking at the byte array and I see the name I have set of the QDockWidet etc... It only seems to be able to set the size of the dock when it's floating otherwise it always goes to the minimum width while docked. It does save whether it's floating and where it's docked, but something just isn't letting it set the size.

    @
    //constructor

    QMainWindow* viewMain; // child control for dock, I have a toolbar for the docked window
    QToolBar* viewToolbar;
    QDockWidget* viewDock;
    QViewport* view; // QGLWidget subclassed

    this->setCentralWidget(new QTabWidget(this)); // have the main window central widget set to a tabwidget
    viewDock = new QDockWidget(this);
    viewDock->setObjectName("ViewportDock");

    viewMain = new QMainWindow(viewDock);
    viewMain->setObjectName("ViewportMainWindow");
    viewMain->setWindowFlags(Qt::Widget);

    view = new QViewport(viewMain);
    view->setObjectName("Viewport");

    viewMain->setCentralWidget(view);

    viewToolbar = new QToolBar(viewMain);
    viewToolbar->setObjectName("ViewportToolbar");

    viewMain->addToolBar(viewToolbar);

    viewDock->setWidget(viewMain);

    this->addDockWidget(Qt::RightDockWidgetArea, viewDock);

    // I have a QSetting class, this is just to show when I am calling these
    this->restoreState();
    this->restoreGeometry()
    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Maybe it's a bug or maybe it's the intended behaviour. If you think it's a bug please file a bug and attach a small example that reproduces it. Even better, please get involved on "qt-project.org":http://qt-project.org and contribute a patch that fixes the problem :-)

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Well I think it's the intended behaviour, in that it's not possible to change the size of the QDockWidget when it's docked, but I would think save/restore state would allow for it.

        I find that whenever I undock than dock it always reverts back to the size that I had last set so I am thinking there is a Size variable for each docking spot, perhaps if there were a function to allow us to modify these.

        @
        QMainWindow::setDockSize( Qt::RightDockWidgetArea, int width (or) height );
        @

        Right now it seems the only way to do this is to set the minimum size of the dockwidget to the size you want, than reset it back to default after it's loaded. This seems to be the only way to set the size of a dock area for a QMainWindow.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Well I narrowed down the problem to Visual Studio 2010. For some reason loadState() doesn't want to work there, only for QDockWidgets' size. I have the same code for Visual Studio 2008 and it works fine.

          EDIT:

          I narrowed it down more, the problem isn't IDE specific. The problem is setting a StyleSheet in the main() function for the QMainWindow and than calling restoreState() in the constructor of the QMainWindow. :\ What are the odds.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Yeah stylesheets sometimes have some unexpected side effects. Looks like a bug though. Please "report it":http://bugreports.qt.nokia.com

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              I am still having this problem. Turning off stylesheets didn't work for me. Below is the code fix that let it work for me:

              @

              void MainWindow::showEvent(QShowEvent*)
              {
              QSettings s;
              this->restoreGeometry(s.value("MainWindow/geometry").toByteArray());
              restoreState(s.value("MainWindow/windowState").toByteArray());
              int arraySize = s.beginReadArray("MainWindow/docks");
              QList<QDockWidget*> docks = this->findChildren<QDockWidget*>();
              for(int i = 0; i< arraySize && i < docks.count(); i++)
              {
              s.setArrayIndex(i);
              docks.at(i)->setFixedSize(s.value("size").toSize());
              docks.at(i)->update();
              docks.at(i)->setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
              docks.at(i)->setMinimumSize(1,1);
              }
              s.endArray();
              }

              void MainWindow::closeEvent(QCloseEvent *e)
              {
              QSettings s;
              s.setValue("MainWindow/geometry", this->saveGeometry());
              s.setValue("MainWindow/windowState", saveState());

              s.beginWriteArray("MainWindow/docks");
              QList<QDockWidget*> docks = this->findChildren<QDockWidget*>();
              for(int i = 0; i < docks.size(); i++)
              {
                  s.setArrayIndex(i);
                  s.setValue("size",docks.at(i)->size());
              }
              s.endArray();
              

              }
              @

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                I am still having this problem. Turning off stylesheets didn't work for me. Below is the code fix that let it work for me:

                @

                void MainWindow::showEvent(QShowEvent*)
                {
                QSettings s;
                this->restoreGeometry(s.value("MainWindow/geometry").toByteArray());
                restoreState(s.value("MainWindow/windowState").toByteArray());
                int arraySize = s.beginReadArray("MainWindow/docks");
                QList<QDockWidget*> docks = this->findChildren<QDockWidget*>();
                for(int i = 0; i< arraySize && i < docks.count(); i++)
                {
                s.setArrayIndex(i);
                docks.at(i)->setFixedSize(s.value("size").toSize());
                docks.at(i)->update();
                docks.at(i)->setMaximumSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
                docks.at(i)->setMinimumSize(1,1);
                }
                s.endArray();
                }

                void MainWindow::closeEvent(QCloseEvent *e)
                {
                QSettings s;
                s.setValue("MainWindow/geometry", this->saveGeometry());
                s.setValue("MainWindow/windowState", saveState());

                s.beginWriteArray("MainWindow/docks");
                QList<QDockWidget*> docks = this->findChildren<QDockWidget*>();
                for(int i = 0; i < docks.size(); i++)
                {
                    s.setArrayIndex(i);
                    s.setValue("size",docks.at(i)->size());
                }
                s.endArray();
                

                }
                @

                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