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. QML Grid: Grid contains more visible items than rows*columns
Forum Updated to NodeBB v4.3 + New Features

QML Grid: Grid contains more visible items than rows*columns

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 678 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.
  • SeDiS Offline
    SeDiS Offline
    SeDi
    wrote on last edited by SeDi
    #1

    Hi,
    i am using a square Grid, which dimension (row&column count) is being set by the user via a SpinBox.
    See screenshot below.

    When I decrease the dimension (e.g. 6 down to 5), i recieve two warnings:

    QML Grid: Grid contains more visible items (36) than rows*columns (30)
    QML Grid: Grid contains more visible items (30) than rows*columns (25)
    

    This does not happen when increasing the dimension.
    Here's the relevant code part:

    Grid {
        id: myGrid
        property int dimension: Controller ? Controller.dimension : 0
        rows: dimension
        columns: dimension
        Repeater {
            model: myGrid.columns * myGrid.rows
            Rectangle {
                //...
            }
        }
    }
    

    In this version the local property dimension is retrieved from a Q_PROPERTY in my c++ Controller.
    _

    I have then tried changing the Grid's model to access the Q_PROPERTY directly:

    model: Controller.dimension * Controller.dimension
    

    Now I recieve a (here: single!) warning when increasing (here: 5 up to 6) the dimension:

    QML Grid: Grid contains more visible items (36) than rows*columns (30)
    

    In this version, I don't get a warning when decreasing the dimension, so almost the other way round.
    _

    As a third shot, I have simplified the code into directly referencing the SpinBox - the same happens:

    Grid {
        id: myGrid
        rows: mySpinBox.value
        columns: mySpinBox.value
        Repeater {
            model: mySpinBox.value * mySpinBox.value
            Rectangle {
                //...
            }
        }
    }
    

    I can't see, what I am doing wrong...
    How can I coerce the Grid into getting its act together before issuing a warning?

    Grid.png

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #3

      What if you remove rows: dimension from your Grid?
      This way the number of children will not be constrained and your delegates will still be correctly positioned since only the columns number is used in a left to right flow.

      mzimmersM 1 Reply Last reply
      1
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by mzimmers
        #2

        I think you misunderstand what you are increasing here: you're increasing the model size, ie, the number of elements in the array, if you will. Your grid can contain 5*5 elements, but when you increase your model size (with the spin box), you get the warning.

        1 Reply Last reply
        1
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #3

          What if you remove rows: dimension from your Grid?
          This way the number of children will not be constrained and your delegates will still be correctly positioned since only the columns number is used in a left to right flow.

          mzimmersM 1 Reply Last reply
          1
          • GrecKoG GrecKo

            What if you remove rows: dimension from your Grid?
            This way the number of children will not be constrained and your delegates will still be correctly positioned since only the columns number is used in a left to right flow.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #4

            @GrecKo looking at his code more closely, I wonder if he's experiencing a bit of a race condition. In one of his examples, both the grid dimensions and the model size are set from the SpinBox. If he increases the SpinBox, and the model is updated before the dimensions, he'd get an error. Similarly if he decreases the SpinBox, and the dimensions are updated first, he'd also get an error.

            1 Reply Last reply
            1
            • GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by
              #5

              Yes that's what I assumed. My guess is that the warnings are just sanity checks enabled when both columns and rows are set, but failing the check has no actual impact. Dues to the non-deterministic binding order evaluation the number of children and grid cells are not synchronized like you explained.

              1 Reply Last reply
              1
              • SeDiS SeDi has marked this topic as solved on
              • SeDiS Offline
                SeDiS Offline
                SeDi
                wrote on last edited by
                #6

                Thanks to you both!
                Removing

                rows: Controller ? Controller.dimension : 0
                

                did the trick.
                It's like parenting: sometimes you just have to trust without setting redundant constraints.

                mzimmersM 1 Reply Last reply
                1
                • SeDiS SeDi

                  Thanks to you both!
                  Removing

                  rows: Controller ? Controller.dimension : 0
                  

                  did the trick.
                  It's like parenting: sometimes you just have to trust without setting redundant constraints.

                  mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #7

                  @SeDi said in QML Grid: Grid contains more visible items than rows*columns:

                  It's like parenting: sometimes you just have to trust without setting redundant constraints.

                  That's actually a very good insight - when you use Layouts in QML, you're giving QML permission to handle some things on its own, without as much specific direction from the programmer. They take some getting used to, but they can offer a lot in return.

                  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