Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Column Width Matching with Children

    QML and Qt Quick
    2
    6
    878
    Loading More Posts
    • 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.
    • S
      shahriar25 last edited by

      Hi. I want to create something like a contextmenu that is a Column and I want the delegate to be a Label and I want the column's width be the delegate's width that has the maximum width among the others. how can I do that?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Doesn't QMenu already provide what you need for a contextual menu ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • S
          shahriar25 last edited by shahriar25

          Hi @SGaist
          I know that it does but I want to create my own and more importantly I want to know how to do that because I will need it elsewhere

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Why do you want to create your own ?

            You take a look a QMenu's sources.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • S
              shahriar25 last edited by

              Hi @SGaist
              I needed it to create something like a dialog
              I looked at the QMenu's source but it didn't help. but then I figured it out after some thinking:

              import QtQuick 2.7
              import QtQuick.Controls 2.0

              Rectangle {
              id: root
              clip: true

              color: "cyan"
              
              width: listView.width
              height: listView.height
              
              property color textColor: "black"
              property var items: [
                  "Open", "Save", "Exit"
              ]
              
              Label{
                  id: testLabel
              
                  visible: false
              
                  text: "test"
              }
              
              ListView{
                  id: listView
              
                  width: 0
                  height: (testLabel.height*3/2)*count
              
                  anchors.centerIn: parent
              
                  model: items
              
                  delegate: BaseButton{
                      id: base
              
                      mainColor: root.color
              
                      width: label.width+label.height/2
                      height: label.height*3/2
              
                      Label{
                          id: label
              
                          anchors.centerIn: parent
              
                          text: items[index]
              
                          color: root.textColor
                      }
              
                      Component.onCompleted: listView.width = base.width>listView.width ? base.width:listView.width
                  }
              }
              

              }

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Sorry, my bad, I somehow missed that you posted that on the QtQuick sub-forum.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post