How to store Windowlayout?



  • Hey guys,

    I have a qtquick application for windows.
    I would like to store the window position and size when I close my application.
    In c++ I would use QSettings but I have no idea how I can save these settings from QML.
    As an alternative I can save the windowlayout from c++ but I don't know how I get the position of my mainwindow from c++.
    Maybe I can create some a slots (windowPosLeft, windowPosTop, windowWidth, windowHeight) and connect it in qml.

    What is the recommended way?

    CU
    mts



  • Qt.labs.settings, just bind needed values to properties of Settings object.



  • This will save it for you, just import "import Qt.labs.settings 1.0", then store there the values you are interested on.

    http://doc.qt.io/qt-5/qml-qt-labs-settings-settings.html

    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import Qt.labs.settings 1.0
    
    ApplicationWindow {
        id: window
    
        width: 360
        height: 360
    
        Settings {
            property alias x: window.x
            property alias y: window.y
            property alias width: window.width
            property alias height: window.height
        }
    }
    


  • Thanks! Looks exactly what I was looking for.

    CU
    mts


Log in to reply
 

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