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. How to store Windowlayout?
Forum Updated to NodeBB v4.3 + New Features

How to store Windowlayout?

Scheduled Pinned Locked Moved QML and Qt Quick
windowlayoutqsettings
4 Posts 3 Posters 1.6k 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.
  • T Offline
    T Offline
    themts
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      morte
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Iktwo
        wrote on last edited by
        #3

        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
            }
        }
        
        1 Reply Last reply
        0
        • T Offline
          T Offline
          themts
          wrote on last edited by
          #4

          Thanks! Looks exactly what I was looking for.

          CU
          mts

          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