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. [Solved] Scrollable Grid in Qt?

[Solved] Scrollable Grid in Qt?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.9k 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.
  • M Offline
    M Offline
    mozeni
    wrote on 6 Mar 2014, 05:25 last edited by
    #1

    Hi,
    I'm trying to implement a scrollable (and flickable) grid
    I was able to do so with a model/delegate set up, but I was wondering if its possible with Grid{}

    This is what I have so far:

    @Flickable {
    anchors.fill: parent
    flickableDirection: Flickable.VerticalFlick
    boundsBehavior: Flickable.DragOverBounds
    clip: true
    Grid {
    columns: 3
    width: parent.width0.32; height: parent.height0.32
    spacing: parent.width*0.01
    Layout1 {}
    Layout2 {}
    Layout3 {}
    Layout4 {}
    Layout5 {}
    Layout6 {}
    Layout7 {}
    Layout8 {}
    Layout9 {}
    Layout10 {}
    Layout11 {}
    Layout12 {}
    Layout13 {}
    }
    }@

    Right now this allows me to flick, but it always bounces back to the top of the list and I dont want it to do that and I can't use the mouse wheel either to scroll down?

    How can I stop the rebound effect and also be able to use the mouse wheel to scroll with this Grid if possible?

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mozeni
      wrote on 6 Mar 2014, 06:59 last edited by
      #2

      Having tried to just go with the model/delegate way of getting the scrolling and no rebound effect I wanted got me closer to what I want to see. But with the model/delegate method, for some reason, the actual qml files don't actually create the shapes that I want them to. running the qml files individually gets the me shapes, but running it in the following way ends up with no shapes showing up:

      @FolderListModel {
      id: folderModel
      folder: "MainscreenLayouts"
      nameFilters: [".qml"]
      }
      Item {
      width: parent.width
      0.4; height: parent.height0.55
      anchors.top: instructions.bottom
      anchors.left: instructions.left
      GridView {
      id: gridModel
      snapMode: ListView.SnapToItem
      boundsBehavior: Flickable.StopAtBounds
      anchors.fill: parent
      clip: true
      model: folderModel
      delegate: fileDelegate
      Rectangle {
      id: scrollbar
      x: gridModel.width
      0.96; y: gridModel.visibleArea.yPosition * gridModel.height
      radius: 7
      width: 10
      height: gridModel.visibleArea.heightRatio * gridModel.height
      opacity: 0.7
      color: "black"
      }
      }
      }

      Component {
          id: fileDelegate
          Loader {
              source: folderModel.folder + "/" + fileName
          }
      }@
      

      any help would be great
      thx

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on 6 Mar 2014, 07:51 last edited by
        #3

        The reason it bounces up is because the Flickable doesn't know how big its content area is. You can fix this by setting contentHeight on the Flickable:

        @
        import QtQuick 2.0
        import QtQuick.Controls 1.0
        Flickable {
        anchors.fill: parent
        flickableDirection: Flickable.VerticalFlick
        boundsBehavior: Flickable.DragOverBounds
        clip: true
        contentHeight: grid.height
        Grid {
        id: grid
        columns: 2
        width: parent.width0.32;
        spacing: parent.width
        0.01
        Repeater {
        model: 20
        Rectangle {width: 100; height: 100 ; border.width: 1}
        }
        }
        }
        @

        Note that you should not set the height property on the Grid, as the height of the grid itself should depend on how many items it contains. Especially when you have locked the vertical column count.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mozeni
          wrote on 6 Mar 2014, 16:51 last edited by
          #4

          For the code you provide it works great, but now what if I'm trying to fill the grid with shapes created by other QML files in a separate folder called MainscreenLayouts

          @import QtQuick 2.0
          import QtQuick.Controls 1.0
          import "MainscreenLayouts"

          Item {
          id: questions3
          anchors.fill: parent
          //Layout Options
          Text {
          id: instructions
          x: parent.width0.07; y: parent.height0.20
          font.pixelSize: parent.height0.023
          color: "gray"
          text: "Select a layout"
          }
          Item {
          width: parent.width
          0.4; height: parent.height0.55
          anchors.top: instructions.bottom
          anchors.left: instructions.left
          Flickable {
          anchors.fill: parent
          flickableDirection: Flickable.VerticalFlick
          boundsBehavior: Flickable.DragOverBounds
          clip: true
          contentHeight: grid.height
          Grid {
          id: grid
          columns: 3
          width: parent.width
          0.3;
          spacing: parent.width*0.01
          Component{
          Layout1{}
          Layout2{}
          Layout3{}
          Layout4{}
          Layout5{}
          Layout6{}
          Layout7{}
          Layout8{}
          Layout9{}
          Layout10{}
          Layout11{}
          Layout12{}
          Layout13{}
          }
          }
          }
          }
          }@

          So there are 13 layouts to choose from, is there a way to show them, cuz individually I can see the shapes generated by LayoutX{}, but in the grid I can not?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mozeni
            wrote on 6 Mar 2014, 18:46 last edited by
            #5

            nvm i got it!
            Thanks for the help with the scrolling :D

            1 Reply Last reply
            0

            1/5

            6 Mar 2014, 05:25

            • Login

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