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. Set attached property in function
Forum Updated to NodeBB v4.3 + New Features

Set attached property in function

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 752 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.
  • K Offline
    K Offline
    krobinson
    wrote on last edited by
    #1

    In QML is it possible to set an attached property from a function? For example Layout.maximumHeight. If I have a function.

    function setMaxHeight()
    {
        //Can I set Layout.maximumHeight on a component here?
    }
    
    ? 1 Reply Last reply
    1
    • K krobinson

      In QML is it possible to set an attached property from a function? For example Layout.maximumHeight. If I have a function.

      function setMaxHeight()
      {
          //Can I set Layout.maximumHeight on a component here?
      }
      
      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @krobinson Hi! That's easy:

      import QtQuick 2.3
      import QtQuick.Window 2.2
      import QtQuick.Layouts 1.2
      import QtQuick.Controls 1.4
      
      Window {
          visible: true
          width: 600
          height: 400
          color: "gray"
      
          function myFunction(x) {
              myItem.Layout.preferredWidth = x
          }
      
          RowLayout {
              anchors.fill: parent
              Rectangle {
                  color: 'orange'
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  Layout.minimumWidth: 50
              }
              Rectangle {
                  id: myItem
                  color: 'plum'
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  Layout.minimumWidth: 50
              }
          }
      
          Row {
              Button {
                  text: "Click me!"
                  onClicked: myFunction(300)
              }
              Button {
                  text: "Close"
                  onClicked: Qt.quit()
              }
          }
      }
      
      1 Reply Last reply
      2
      • K Offline
        K Offline
        krobinson
        wrote on last edited by
        #3

        Thanks, I swear I tried that. That's nice and easy.

        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