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. Item's property
Forum Updated to NodeBB v4.3 + New Features

Item's property

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 632 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
    tacdin
    wrote on last edited by
    #1

    Hi everyone! For example, I have a file named Test1.qml where I want to assign the width of an item to another item in a file named Test2.qml. What should I do for this?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use Test2 component inside Test1.qml:

      // Test1.qml
      Item {
        Test2 {
          width: 100
        }
      }
      

      ... or if that is not practical in your theoretical example, you can use some common base (main.qml? Some "parent" component which "sees" both Test1 and Test2 instances) and assign it:

      // main.qml
      
      Rectangle {
        Test1 {
          id: test1
        }
      
        Test2 {
          width: test1.width
        }
      }
      

      I'm pretty sure this is not what you are asking, though. Please try being a little more precise - maybe share part of your code, or say what you are trying to do? Without a concrete example it's a bit hard to explain, there're just too many possibilities.

      (Z(:^

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tacdin
        wrote on last edited by
        #3

        First of all, thank you for your reply.

        I did not share the codes because they are not regular. You are right, it can reach a more comfortable solution with codes. I can explain it with an image like this. I have a TabBar. It has buttons. For example, when the relevant button is clicked, the stackview.push(Test2.qml) function calls another qml page. What I want is to give the width of the qml page that each button calls with reference to the width of the TabBar. So I want to be able to access the width of the TabBar inside the Test2.qml page. I'm using stackview.push() I don't want to nest both pages.

        deneme.png

        1 Reply Last reply
        0
        • ndiasN Offline
          ndiasN Offline
          ndias
          wrote on last edited by ndias
          #4

          Hi @tacdin ,

          On main window you can use a ColumnLayout to contain tab bar and Test2.qml item.
          You should set Layout.fillWidth: true on tabbar and Layout.fillHeight: true; Layout.alignment: Qt.AlignCenter on your stackview.

          EDIT: You can find a sample how to use ColumnLayout bellow:

          import QtQuick
          import QtQuick.Window
          import QtQuick.Layouts
          import QtQuick.Controls
          
          
          
          ApplicationWindow {
              visible: true
              width: 640
              height: 480
          
              ColumnLayout {
                  anchors.fill: parent
                  anchors.margins: 30
          
                  Rectangle {
                      color: "red"
                      height: 30
                      Layout.fillWidth: true
                      Layout.alignment: Qt.AlignCenter
                      Label {
                          anchors.fill: parent
                          color: "black"
                          text: qsTr("Heading 1")
                          verticalAlignment: Text.AlignVCenter
                          horizontalAlignment: Text.AlignHCenter 
                      }
                  }
          
                  Rectangle {
                      color: "green"
                      Layout.fillWidth: true
                      Layout.fillHeight: true
                  }
              }
          }
          

          Regards

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            As @ndias suggests, there is no need here for Tabs to know anything about the tab bar. If you use layouts (or anchors) to make sure TabBar and StackView have the same width, the tab pages will inherit that (and if not, just call width: parent.width in your tab code).

            (Z(:^

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tacdin
              wrote on last edited by
              #6

              Thanks for the suggestions. I will post the result here.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tacdin
                wrote on last edited by
                #7

                Solved. Thank you for your help. @sierdzio @ndias

                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