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 cellHeight not right unless magic number

Gridview cellHeight not right unless magic number

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 861 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.
  • B Offline
    B Offline
    boogerlad
    wrote on last edited by
    #1

    This is the model, OptionsModel.qml
    @import QtQuick 2.2

    ListModel {
    ListElement {
    modifier: "Options"
    stuff: [
    ListElement
    {
    name: "a"
    },
    ListElement
    {
    name: "b"
    },
    ListElement
    {
    name: "c"
    },
    ListElement
    {
    name: "d"
    }
    ]
    }
    ListElement {
    modifier: "Options"
    stuff: [
    ListElement
    {
    name: "a"
    },
    ListElement
    {
    name: "b"
    },
    ListElement
    {
    name: "c"
    },
    ListElement
    {
    name: "d"
    }
    ]
    }
    }@

    In my main.qml, I have
    @GridView
    {
    anchors.top: exit.bottom
    anchors.left: parent.left
    anchors.leftMargin: 20
    anchors.right: parent.right
    anchors.rightMargin: 20
    anchors.bottom: parent.bottom
    clip: true
    interactive: contentHeight > height
    cellWidth: parent.width
    cellHeight: deli.height
    model: OptionsModel {}
    delegate: Rectangle
    {
    id: deli
    height: gob.height + title.height
    width: parent.width
    anchors.left: parent.left
    border.color: "red"
    border.width: 1
    Text
    {
    //anchors.fill: parent
    id: title
    text: modifier
    }
    Grid
    {
    id: gob
    anchors.top: title.bottom
    anchors.left: parent.left
    anchors.right: parent.right
    columns: 2
    spacing: 40
    Repeater
    {
    model: stuff
    Rectangle
    {
    width: 400
    height: 84
    border.color: "gray"
    border.width: 1
    color: "transparent"
    Text
    {
    text: deli.height
    }
    }
    }
    }
    }
    }@
    I end up with !http://i.imgur.com/MMZRnAZ.png( )!

    As soon as I change @cellHeight: deli.height@ to @cellHeight: 222@ , I end up with this !http://i.imgur.com/X0RYFMh.png( )!
    deli.height is equal to 222. I know this because I set the Text element to display it. Why does changing the GridView's cellHeight to a magic number fix it? The spacing is totally wrong in the first picture(second item of the delegate overlaps with first), but the second one is perfect with zero spacing.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      boogerlad
      wrote on last edited by
      #2

      Ah, GridView does not support variable cellHeights. Solved by making a Repeater nested in a Column nested in a Flickable.

      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