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] After using QMainWindow restoreState QDockWidgets added don't end up in expected position
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.3k 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.
  • B Offline
    B Offline
    Boumbles
    wrote on last edited by
    #1

    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.......);
    runtime_widget->setAllowedAreas(Qt::AllDockWidgetAreas);
    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show the store and restore related code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Boumbles
        wrote on last edited by
        #3

        Saving

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

        Loading

        @restoreState(QSettings().value("WindowState").toByteArray());@

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you also do the same for the geometry ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Boumbles
            wrote on last edited by
            #5

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

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

            @restoreGeometry(QSettings().value("WindowGeometry").toByteArray());
            restoreState(QSettings().value("WindowState").toByteArray());@

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you set a name on your dock widgets ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Boumbles
                wrote on last edited by
                #7

                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!

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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