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. GridView with model and additional items
Forum Updated to NodeBB v4.3 + New Features

GridView with model and additional items

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 638 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
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I have a GridView where I add buttons coming from a model. However, I would like to add an additional item to the GridView which has a different type. Is it possible to add this additional item without modifying my model to account for both types?

    YashpalY 1 Reply Last reply
    0
    • M maxwell31

      Hi,

      I have a GridView where I add buttons coming from a model. However, I would like to add an additional item to the GridView which has a different type. Is it possible to add this additional item without modifying my model to account for both types?

      YashpalY Offline
      YashpalY Offline
      Yashpal
      wrote on last edited by
      #2

      @maxwell31 Hi! I'm guessing you're talking about having different delegate components to the GridView based on some conditions. If yes, can you relate the following code.

          Component {
              id: rectCompo
      
              Rectangle {
                  width: 40
                  height: width
                  color: "red"
              }
          }
      
          Component {
              id: roundCompo
      
              Rectangle {
                  width: 80
                  height: width
                  color: "green"
                  radius: width /2
              }
          }
      
          GridView {
              model: 10
              width: 400
              height: width
      
              delegate: Loader {
                  sourceComponent: index % 2 ? rectCompo : roundCompo
              }
          }
      
      1 Reply Last reply
      3
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3

        Ideally, I would like to keep some elements outside of the mode, e.g. have a model and then add some additional items, e.g. buttons

        1 Reply Last reply
        0
        • Shrinidhi UpadhyayaS Offline
          Shrinidhi UpadhyayaS Offline
          Shrinidhi Upadhyaya
          wrote on last edited by
          #4

          Hi @maxwell31 , i guess you need a different component depending upon some condition after the click,below is a sample code needed to achieve your functionality:-

          Button {
              text: "Update"
              anchors.top: gridView.bottom
              anchors.topMargin: 10
          
              onClicked: {
                  gridModel.append( {"redRectVisible": false});
              }
          }
          
          ListModel {
              id: gridModel
          
              ListElement{
                  redRectVisible: true
              }
          
              ListElement{
                  redRectVisible: true
              }
          }
          
          GridView {
              id: gridView
          
              height: 200
              width: 200
              model: gridModel
              cellWidth: 100
              cellHeight: 100
          
              delegate: Item {
                  height: gridView.cellHeight
                  width: gridView.cellWidth
                  Rectangle {
                      height: parent.height
                      width: parent.width
                      color: "red"
                      border.color: "black"
                      visible: redRectVisible
                  }
          
                  Rectangle {
                      height: parent.height
                      width: parent.width
                      color: "green"
                      border.color: "black"
                      visible: !redRectVisible
                  }
              }
          }
          

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          1 Reply Last reply
          2

          • Login

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