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. Need save/restore QMainWindow minimized state
QtWS25 Last Chance

Need save/restore QMainWindow minimized state

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 6.8k Views
  • 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.
  • G Offline
    G Offline
    Gourmand
    wrote on last edited by
    #1

    There are some plugins in my app - each one has main window derived from QMainWindow. I used saveState() and saveGeometry() methods to keep these windows same between app sessions. But no one of this methods gives info about window minimized/shown state. At least in Windows XP SP2. The windows geometry and docks inside windows are saved as well. But if I minimize plugin window - the next time it appeares on screen after restart. I need it will not appear if it was minimized in previous session.

    I want suggest save "minimized" state with saveGeometry() cause it relates mostly to QWidget (not only QMainWindow can be minimized, but some other windowed class too).

    Or I just missed something and this can be already done by other way?
    Any opinion?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Haven't done anything in that area recently, so I might remember wrong.

      QSettings can be used to save the state of QWidget's "minimized" property. Then you just need to read settings on app startup and set the window state according to the saved value.

      (Z(:^

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Here's a link to this property description: http://developer.qt.nokia.com/doc/qt-4.7/qwidget.html#id-85030a7f-dd06-4413-b7d7-00643c524901

        (Z(:^

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gourmand
          wrote on last edited by
          #4

          I use QSettings to save data from saveState() and saveGeometry(). But I was surprised that minimized state is not included to ByteArray returned from saveGeometry().

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gourmand
            wrote on last edited by
            #5

            The QWidget::showMinimized() is not suitable for me. I do not need to show but I need to restore minimized state. Window will be shown later. But I don't see something like QWidget::setMinimized(bool). Therefore I suggest include minimized state to ByteArray returned from QWidget::saveGeometry(). And restore this state in the QWidget::restoreGeometry().

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              Two possibilites:

              • File a suggestion to the "bug tracker":https://bugreports.qt.nokia.com/secure/Dashboard.jspa
              • Do the changes on your own and file a "merge request":http://www.qt-project.org/
              1 Reply Last reply
              0
              • G Offline
                G Offline
                Gourmand
                wrote on last edited by
                #7

                I just wanna discuss this before bugtracking.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gourmand
                  wrote on last edited by
                  #8

                  Temporary solved this using (QWidget::windowState() | Qt::WindowMinimized) but this doesn't look comfortable.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lgeyer
                    wrote on last edited by
                    #9

                    [quote author="Gourmand" date="1321383818"]I just wanna discuss this before bugtracking.[/quote]

                    Well, I'm against this change then.

                    • I see no sense in letting QMainWindow::saveState() store the widgets state as there is no connection to its primary role (state of toolbars and dock widgets) and it is available to QMainWindow only. Such behaviour would be quite inconsistent and confusing.
                    • QWidget::saveGeometry() is responsible for saving a widgets geometry (size and position). The window state of a widget does not influence the geometry and vice versa - these are two independent properties of a widget of thus should have two independent setters and getters (otherwise I couldn't set one without the other).
                    • I do not expect that both, QMainWindow::restoreState() and QWidget::restoreGeometry(), modify the window state of a widget, as it has neither to do with a toolbar and dock widget state (state) or a widgets size and position (geometry).
                    • There is already an existing method for exactly this purpose: QWidget::windowState().
                    • Such a change might break existing applications.

                    What's the difference between
                    @
                    settings.setValue("geometry", widget.saveGeometry());
                    settings.setValue("state", widget.saveState());

                    widget.restoreGeometry(settings.value("geometry").toByteArray());
                    widget.restoreState(settings.value("state").toByteArray());
                    @
                    and
                    @
                    settings.setValue("geometry", widget.saveGeometry());
                    settings.setValue("state", widget.saveState());
                    settings.setValue("windowstate", static_cast<int>(widget.windowState()));

                    widget.restoreGeometry(settings.value("geometry").toByteArray());
                    widget.restoreState(settings.value("state").toByteArray());
                    widget.setWindowState(static_castQt::WindowState(settings.value("windowstate").toInt()));
                    @
                    besides an additional line of code that would justify these serious changes?

                    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