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. Window.width in a property
QtWS25 Last Chance

Window.width in a property

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlwindow
5 Posts 2 Posters 589 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.
  • M Offline
    M Offline
    Moisi
    wrote on 21 Aug 2019, 11:12 last edited by
    #1

    Hi,

    I have a QtObject. This object is use like a model to stock informations used by my application. Among this informations, I want to have the width of the Window item.

    But I'm not able to correctly stock the Window width in a property. When I try to read the property, I got the wrong value.

    Here is my code:

    Window
    {
    	visible: true
    	width: 1300
    	height: 800
    	title: qsTr("Tests")
    
    	Label { text: item.windowWidth; z: 5 }
    
    	property var model: QtObject
    	{
    		id: item
    		property int windowWidth: Window.width // 0
    	}
    }
    
    

    Expected value from the windowWidth property: 1300
    Current value: 0

    I can't understant why I can't have the right value in my property... Did I miss some information about the Window item ?

    Thank you ^^

    O 1 Reply Last reply 21 Aug 2019, 11:24
    0
    • M Offline
      M Offline
      Moisi
      wrote on 21 Aug 2019, 11:37 last edited by
      #3

      @lelev said in Window.width in a property:

      u need to give an id to your Window item and then you can reach it by id

      Wow, it works perfectly, thank you a lot ^^

      Can I ask you why the id is mantatory ? Reading the Window Qml Type information, using Window.width should have work.

      O 1 Reply Last reply 21 Aug 2019, 11:46
      0
      • M Moisi
        21 Aug 2019, 11:12

        Hi,

        I have a QtObject. This object is use like a model to stock informations used by my application. Among this informations, I want to have the width of the Window item.

        But I'm not able to correctly stock the Window width in a property. When I try to read the property, I got the wrong value.

        Here is my code:

        Window
        {
        	visible: true
        	width: 1300
        	height: 800
        	title: qsTr("Tests")
        
        	Label { text: item.windowWidth; z: 5 }
        
        	property var model: QtObject
        	{
        		id: item
        		property int windowWidth: Window.width // 0
        	}
        }
        
        

        Expected value from the windowWidth property: 1300
        Current value: 0

        I can't understant why I can't have the right value in my property... Did I miss some information about the Window item ?

        Thank you ^^

        O Offline
        O Offline
        ODБOï
        wrote on 21 Aug 2019, 11:24 last edited by
        #2

        hi
        @moisi said in Window.width in a property:

        property int windowWidth: Window.width // 0

        you need to give an id to your Window item and then you can reach it by id

        Window {
            id:win
        
            visible: true
            width: 1300
            height: 480
        
            property var model: QtObject
                {
                    id: item
                    property int windowWidth: win.width // 0
                }
        
        
            Component.onCompleted: console.log(item.windowWidth)
        
        }
        
        1 Reply Last reply
        1
        • M Offline
          M Offline
          Moisi
          wrote on 21 Aug 2019, 11:37 last edited by
          #3

          @lelev said in Window.width in a property:

          u need to give an id to your Window item and then you can reach it by id

          Wow, it works perfectly, thank you a lot ^^

          Can I ask you why the id is mantatory ? Reading the Window Qml Type information, using Window.width should have work.

          O 1 Reply Last reply 21 Aug 2019, 11:46
          0
          • M Moisi
            21 Aug 2019, 11:37

            @lelev said in Window.width in a property:

            u need to give an id to your Window item and then you can reach it by id

            Wow, it works perfectly, thank you a lot ^^

            Can I ask you why the id is mantatory ? Reading the Window Qml Type information, using Window.width should have work.

            O Offline
            O Offline
            ODБOï
            wrote on 21 Aug 2019, 11:46 last edited by ODБOï
            #4

            @moisi
            Window is the class name not he object itself,, you want to access a instance of it

            Window {
              Rectangle{
                color : "red"
              }
              Rectangle{
                color : "blue"
             }
            
             Component.onCompleted : {
              // how to change  first rectangle color  ?  Rectangle.color ? but which rectangle ?
             // solution is to give id to you rectangle so you can cible it 
             }
            
            }
            
            
            1 Reply Last reply
            1
            • M Offline
              M Offline
              Moisi
              wrote on 21 Aug 2019, 12:11 last edited by
              #5

              Oh, yep, with this explaination is more clear. Thank you a lot ^^

              1 Reply Last reply
              0

              4/5

              21 Aug 2019, 11:46

              • Login

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