Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]QML Settings Type seems to have no effect on window size.
Forum Update on Monday, May 27th 2025

[SOLVED]QML Settings Type seems to have no effect on window size.

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 2.2k 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by ealione
    #1

    I have decided to use Qt.labs.settings 1.0 to save the state of my window in this manner:

    ApplicationWindow {
        // Main configuration section for the application window
        id: mainwindow
        visible: true // Needed if loading from c++.
    
        property string accentchosen: "#F4511E"
    
        height: Units.dp(600)
        minimumHeight:  Units.dp(500)
        maximumHeight: Units.dp(1200)
        width: Units.dp(800)
        minimumWidth: Units.dp(300)
        maximumWidth: Units.dp(1080)
    
        Settings {
            id: settings
            property alias x: mainwindow.x
            property alias y: mainwindow.y
            property alias width: mainwindow.width
            property alias height: mainwindow.height
            property alias accentchosen: mainwindow.accentchosen
        }
    

    This code will result in my application starting on the x and y position it was last on, but its width and height do not seem to follow their last state, instead they keep being 600x800.

    According to the docs the second time, and each subsequent time after that it should remember its state. Am I doing something wrong?

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      Does it work without Units.dp()?

      1 Reply Last reply
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by
        #3

        @ealione said:

        Units.dp

        No if the units are specified that way it does not work, but thats the issue. Why is it not working if I assign my units using Units.dp() and if there is something that can be done about it.

        1 Reply Last reply
        0
        • jpnurmiJ Offline
          jpnurmiJ Offline
          jpnurmi
          wrote on last edited by
          #4

          How is Units.dp() implemented?

          1 Reply Last reply
          0
          • ealioneE Offline
            ealioneE Offline
            ealione
            wrote on last edited by
            #5

            This function comes from the qml-material module that can be found here. It will simply return a new number based on the pixel density of the device, in order for the units to be screen independent. Now since what I get is a number I imagined nothing would go wrong.

            PS: I should have provided all this info from the start, I apologize about that.

            jpnurmiJ 1 Reply Last reply
            0
            • ealioneE ealione

              This function comes from the qml-material module that can be found here. It will simply return a new number based on the pixel density of the device, in order for the units to be screen independent. Now since what I get is a number I imagined nothing would go wrong.

              PS: I should have provided all this info from the start, I apologize about that.

              jpnurmiJ Offline
              jpnurmiJ Offline
              jpnurmi
              wrote on last edited by
              #6

              @ealione Ok, so it's a non-constant expression ie. a property binding, so I'm afraid the binding wins and overrides the value that was read and initialized by the settings.

              1 Reply Last reply
              1
              • ealioneE Offline
                ealioneE Offline
                ealione
                wrote on last edited by
                #7

                I see, so I should find another way of saving this data. Thanks for the answer jpnurmi.

                jpnurmiJ 1 Reply Last reply
                0
                • ealioneE ealione

                  I see, so I should find another way of saving this data. Thanks for the answer jpnurmi.

                  jpnurmiJ Offline
                  jpnurmiJ Offline
                  jpnurmi
                  wrote on last edited by
                  #8

                  @ealione It's still worth opening a ticket at bugreports.qt.io though. If it cannot be fixed, it probably should be noted in the docs. :)

                  1 Reply Last reply
                  0
                  • ealioneE Offline
                    ealioneE Offline
                    ealione
                    wrote on last edited by ealione
                    #9

                    OK, Just created a new issue https://bugreports.qt.io/browse/QTBUG-51697

                    1 Reply Last reply
                    1

                    • Login

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