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. SwipeView with GridView
Qt 6.11 is out! See what's new in the release blog

SwipeView with GridView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 306 Views
  • 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by Circuits
    #1

    Hey guys, I am just toying around with SwipeView and GridView neither of which I am very familiar with. What I am attempting to do right now is get multiple pages. Each new page would be a grid view. Eventually I would like to have each new page have different colors/sized Rectangles but at the moment I can't get a single page working.

    For some reason my view is only showing a single white Rectangle. Here is the code:

    
      ListModel {
        id: theModel
    
          ListElement {
              color: "red"
          }
          ListElement {
              color: "blue"
          }
          ListElement {
              color: "green"
          }
      }
    
    
      SwipeView
      {
        id: view
        currentIndex: 1
        anchors.fill: parent
    
        GridView {
              width: 300; height: 200
    
              model: theModel
              delegate: Rectangle
              {
                anchors.centerIn: parent
                width: 50
                height: 50
    
                color: color
    
              }
          }
      }
      
      PageIndicator {
          id: indicator
    
          count: view.count
          currentIndex: view.currentIndex
    
          anchors.bottom: view.verticalCenter
          anchors.horizontalCenter: parent.horizontalCenter
      }
    

    How can I force the GridView delegate to alter it's color based on the color property seen in

    theModel
    

    and why am I only seeing one Rectangle?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Circuits
      wrote on last edited by
      #2

      Ah I think I understand now. It would seem that using predefined properties is not okay and I was wrong about how the GridView was anchoring itself. Something like this works:

      ListModel {
      id: theModel

        ListElement {
            name: "red"
            breadth: 75
            ceiling: 120
        }
        ListElement {
            name: "blue"
            breadth: 100
            ceiling: 120
        }
        ListElement {
            name: "green"
            breadth: 200
            ceiling: 120
        }
      

      }

      SwipeView
      {
      id: view
      currentIndex: 1
      anchors.fill: parent

      GridView {
            width: 300; height: 200
      
            anchors.fill: parent
      
            model: theModel
            delegate: Rectangle
            {
      
              width: breadth
              height: ceiling
              color: name
      
            }
        }
      

      }

      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