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



  • 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?



  • Does it work without Units.dp()?



  • @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.



  • How is Units.dp() implemented?



  • 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.



  • @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.



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



  • @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. :)



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.