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. Column Width Matching with Children
Forum Updated to NodeBB v4.3 + New Features

Column Width Matching with Children

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.3k Views 2 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.
  • S Offline
    S Offline
    shahriar25
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        shahriar25
        wrote on last edited by shahriar25
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • S Offline
            S Offline
            shahriar25
            wrote on last edited by
            #5

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0

              • Login

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