Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-65121

Replacing a GridLayout cell with a repeater complains

    XMLWordPrintable

Details

    • cc77a0bc549ce8f0b218661e7ae0e82e5b89e0da (qt/qtdeclarative/dev) a5d2fd816bcbee6026894927ae5d049536bfc7ea (qt/qtdeclarative/5.15)
    • Shovelling Snow, Q1/2020 Finale, Q2/2020 kick off

    Description

      The example uses two Repeaters to set the columns of a GridLayout. The first repeater does the first column and the second does the second column. Inside the repeater the cell is set explicitly with Layout.row and Layout.column.

       

      The code below can also be found in this gist/git repo. https://gist.github.com/Siecje/27f41128863bf8bcbe3ab2a054c67dd7

      The output is as follows

      QGridLayoutEngine::addItem: Cell (0, 0) already taken
      QGridLayoutEngine::addItem: Cell (0, 0) already taken
      QGridLayoutEngine::addItem: Cell (0, 1) already taken
      QGridLayoutEngine::addItem: Cell (0, 1) already taken
      

      Run this file with qmlscene and then click the button to see the error in the terminal.

      import QtQuick 2.7
      import QtQuick.Controls 1.4
      import QtQuick.Layouts 1.3 as Layouts
      
      Item {
          id: base
          property var categories: ['one', 'two', 'three']
          property var values: [1, 2, 3]
          width: 800
          height: 600
      
          Column {
            Button {
              text: "Cause error output"
              onClicked: {
                base.categories = ['eleven', 'twelve']
                base.values = [11, 12]
              }
            }
            Button {
              text: "DOES NOT Cause error output"
              onClicked: {
                base.categories = ['eleven']
                base.values = [11]
              }
            }
          }
      
          Layouts.GridLayout {
            anchors.fill: parent
            columns: 2
      
            // CATEGORY LABELS...
            Repeater {
                model: base.categories // modelData will be the categories
                Item {
                    Layouts.Layout.row: index
                    Layouts.Layout.column: 0
                    Layouts.Layout.preferredWidth: _categoryLabel.width
                    Layouts.Layout.fillHeight: true
                    // The actual category label...
                    Text {
                        id: _categoryLabel
                        height: parent.height
                        anchors.right: parent.right
                        text: modelData
                        verticalAlignment: Text.AlignVCenter
                        font.pointSize: 27
                        leftPadding: 10
                    }
                }
            }
      
            Repeater {
                model: base.values // modelData will be the values
                Item {
                    Layouts.Layout.row: index
                    Layouts.Layout.column: 1
                    Layouts.Layout.preferredWidth: _categoryLabel.width
                    Layouts.Layout.fillHeight: true
                    // The actual value label...
                    Text {
                        id: _categoryLabel
                        height: parent.height
                        anchors.right: parent.right
                        text: modelData
                        verticalAlignment: Text.AlignVCenter
                        font.pointSize: 27
                        leftPadding: 10
                    }
                }
            }
        }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            smd Jan Arve
            code Cody Scott
            Votes:
            17 Vote for this issue
            Watchers:
            16 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes