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. Random Customs controls in a row.
Forum Updated to NodeBB v4.3 + New Features

Random Customs controls in a row.

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

    Hello, I have a requirement where it is required to show controls with equally height in a fixed size row.
    The controls can be random based on my 7 different conditions for e.g A,B,C ,D,E,F,G,H,I are the controls then

    Condition 1
    A,B,C,D,E

    Condition 2
    A,E,C,F

    Condition 3
    B,C,F,H

    like this. Now because of number of permutation and combinations it is impossible to use the QML states there. The number of states will be increased and it becomes a mess. Is there any other way this can be handled.?

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #3

      Okay, I see the problem. You will have to get creative with loaders and things repeaters:

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      
      Window {
          visible: true
          width: 800
          height: 600
          title: qsTr("Item Ordering")
      
          Component {
              id: itemA
              Text {
                  width: 100
                  height: 20
                  text: "itemA"
              }
          }
          Component {
              id: itemB
              Text {
                  width: 100
                  height: 20
                  text: "itemB"
              }
          }
          Component {
              id: itemC
              Text {
                  width: 100
                  height: 20
                  text: "itemC"
              }
          }
          Component {
              id: itemD
              Text {
                  width: 100
                  height: 20
                  text: "itemD"
              }
          }
          Component {
              id: itemE
              Text {
                  width: 100
                  height: 20
                  text: "itemE"
              }
          }
          Component {
              id: itemF
              Text {
                  width: 100
                  height: 20
                  text: "itemF"
              }
          }
          Component {
              id: itemG
              Text {
                  width: 100
                  height: 20
                  text: "itemG"
              }
          }
          Component {
              id: itemH
              Text {
                  width: 100
                  height: 20
                  text: "itemH"
              }
          }
      
          Column {
      
              Row {
                  Button {
                      text: "Condition 1"
                      onClicked: mainrow.state = "Condition1"
                  }
                  Button {
                      text: "Condition 2"
                      onClicked: mainrow.state = "Condition2"
                  }
                  Button {
                      text: "Condition 3"
                      onClicked: mainrow.state = "Condition3"
                  }
                  Button {
                      text: "Condition None"
                      onClicked: mainrow.state = ""
                  }
              }
      
              Row {
                  id: mainrow
      
                  property var loaded: []
      
                  onLoadedChanged: console.log(loaded)
      
                  states: [
                      State {
                          name: "Condition1"
                          PropertyChanges {
                              target: mainrow
                              loaded: [itemA,itemB,itemC,itemD,itemE]
                          }
                      },
                      State {
                          name: "Condition2"
                          PropertyChanges {
                              target: mainrow
                              loaded: [itemA,itemE,itemC,itemF]
                          }
                      },
                      State {
                          name: "Condition3"
                          PropertyChanges {
                              target: mainrow
                              loaded: [itemB,itemC,itemF,itemH]
                          }
                      }
                  ]
      
                  Repeater {
                      model: mainrow.loaded.length
      
                      delegate: Loader {
                          sourceComponent: mainrow.loaded[index]
                      }
                  }
              }
          }
      }
      

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #2
        Row {
          Item {
            id: control_a
            visible: control_a_enabled
          }
          Item {
            id: control_b
            visible: control_b_enabled
          }
          // etc
        }
        

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #3

          Okay, I see the problem. You will have to get creative with loaders and things repeaters:

          import QtQuick 2.12
          import QtQuick.Window 2.12
          import QtQuick.Controls 2.12
          
          Window {
              visible: true
              width: 800
              height: 600
              title: qsTr("Item Ordering")
          
              Component {
                  id: itemA
                  Text {
                      width: 100
                      height: 20
                      text: "itemA"
                  }
              }
              Component {
                  id: itemB
                  Text {
                      width: 100
                      height: 20
                      text: "itemB"
                  }
              }
              Component {
                  id: itemC
                  Text {
                      width: 100
                      height: 20
                      text: "itemC"
                  }
              }
              Component {
                  id: itemD
                  Text {
                      width: 100
                      height: 20
                      text: "itemD"
                  }
              }
              Component {
                  id: itemE
                  Text {
                      width: 100
                      height: 20
                      text: "itemE"
                  }
              }
              Component {
                  id: itemF
                  Text {
                      width: 100
                      height: 20
                      text: "itemF"
                  }
              }
              Component {
                  id: itemG
                  Text {
                      width: 100
                      height: 20
                      text: "itemG"
                  }
              }
              Component {
                  id: itemH
                  Text {
                      width: 100
                      height: 20
                      text: "itemH"
                  }
              }
          
              Column {
          
                  Row {
                      Button {
                          text: "Condition 1"
                          onClicked: mainrow.state = "Condition1"
                      }
                      Button {
                          text: "Condition 2"
                          onClicked: mainrow.state = "Condition2"
                      }
                      Button {
                          text: "Condition 3"
                          onClicked: mainrow.state = "Condition3"
                      }
                      Button {
                          text: "Condition None"
                          onClicked: mainrow.state = ""
                      }
                  }
          
                  Row {
                      id: mainrow
          
                      property var loaded: []
          
                      onLoadedChanged: console.log(loaded)
          
                      states: [
                          State {
                              name: "Condition1"
                              PropertyChanges {
                                  target: mainrow
                                  loaded: [itemA,itemB,itemC,itemD,itemE]
                              }
                          },
                          State {
                              name: "Condition2"
                              PropertyChanges {
                                  target: mainrow
                                  loaded: [itemA,itemE,itemC,itemF]
                              }
                          },
                          State {
                              name: "Condition3"
                              PropertyChanges {
                                  target: mainrow
                                  loaded: [itemB,itemC,itemF,itemH]
                              }
                          }
                      ]
          
                      Repeater {
                          model: mainrow.loaded.length
          
                          delegate: Loader {
                              sourceComponent: mainrow.loaded[index]
                          }
                      }
                  }
              }
          }
          

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1

          • Login

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