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. How to apply the same background to all DelegateChioces in DelegateChooser?
Forum Updated to NodeBB v4.3 + New Features

How to apply the same background to all DelegateChioces in DelegateChooser?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 527 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.
  • P Offline
    P Offline
    Puya
    wrote on last edited by
    #1

    Hi I have a DelegateChooser for a TableView with 10-20 different DelegateChoices. How can I apply the same background to all the choices? I want to avoid having to add the same background to all choices as that is a lot of repeater code and a maintenance headache:

    DelegateChoice: {
       Item {
             Rectangle { id: background; anchors.fill: parent; color: "blue" }
             Choice1 {}
        }
        ...
       Item {
             Rectangle { id: background; anchors.fill: parent; color: "blue" }
             Choice20 {}
        }
    }
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by fcarney
      #2

      @Puya said in How to apply the same background to all DelegateChioces in DelegateChooser?:

      Item {
      Rectangle { id: background; anchors.fill: parent; color: "blue" }
      Choice20 {}
      }

      DefaultChoiceItem.qml:

      Item {
               Rectangle { id: background; anchors.fill: parent; color: "blue" }
      
          }
      

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Puya
        wrote on last edited by
        #3

        @fcarney Is there no way to avoid having to wrap every choice individually?

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4
              property var choices: ({
                  {role:"info", delegate:ItemDelegate},
                  {role:"switch", delegate:SwitchDelegate}, 
                  {role:"swipe", delegate:SwipeDelegate}
              })
          
              ...
              DelegateChooser {
                  id: chooser
                  role: "type"
                  Repeater {
                      model: choices
                      DelegateChoice { roleValue: modelData.role;  delegate: modelData.delegate }
                  }
              }
          

          I don't know if this will work. But it might. Still requires to make a ton of choices as Components or QML files.

          This is a modification of the example here.

          C++ is a perfectly valid school of magic.

          P 1 Reply Last reply
          0
          • fcarneyF fcarney
                property var choices: ({
                    {role:"info", delegate:ItemDelegate},
                    {role:"switch", delegate:SwitchDelegate}, 
                    {role:"swipe", delegate:SwipeDelegate}
                })
            
                ...
                DelegateChooser {
                    id: chooser
                    role: "type"
                    Repeater {
                        model: choices
                        DelegateChoice { roleValue: modelData.role;  delegate: modelData.delegate }
                    }
                }
            

            I don't know if this will work. But it might. Still requires to make a ton of choices as Components or QML files.

            This is a modification of the example here.

            P Offline
            P Offline
            Puya
            wrote on last edited by
            #5

            @fcarney How would that work with the delegate (a QML component) coming from the model (C++ object)?

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

              @Puya said in How to apply the same background to all DelegateChioces in DelegateChooser?:

              How would that work with the delegate (a QML component) coming from the model (C++ object)?

              No idea. I don't know what that means.

              C++ is a perfectly valid school of magic.

              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