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

GridView considers items in its header as valid indexes in indexAt(int, int)

XMLWordPrintable

    • 7ea4e48b69 (qt/tqtc-qtdeclarative/dev)

      GridView's indexAt(int, int) method considers items in its header as valid indexes; clicking on the day names in the example below will return indexes from 0 to 6, and then 7 and above for the actual contents of the GridView.

      Also, clicking the last row of the GridView will give -1 for every item.

      import QtQuick 2.0
      
      Rectangle {
          width: 450
          height: 500
      
          GridView {
              id: view
              anchors.centerIn: parent
              width: cellWidth * 7
              height: cellHeight * (6 + 1) // (6 week row, 1 header row)
              cellWidth: 50
              cellHeight: cellWidth
      
              MouseArea {
                  id: area
                  anchors.fill: parent
      
                  onClicked: {
                      print(view.indexAt(mouse.x, mouse.y));
                  }
              }
      
              model: ListModel {
                  Component.onCompleted: {
                      for (var i = 0; i < 42; ++i)
                          append({name: i})
                  }
              }
      
              delegate: Item {
                  id: row
                  width: view.cellWidth - 2
                  height: view.cellHeight - 2
      
                  Rectangle {
                      anchors.fill: parent
                      color: "grey"
                  }
      
                  Text {
                      anchors.centerIn: parent
                      text: name
                  }
              }
      
              header: Row {
                  id: headerRow
                  width: view.width
                  height: view.cellHeight
                  Repeater {
                      id: repeater
                      model: ListModel {
                          Component.onCompleted: {
                              var a = ["Mon", "Tues", "Wed", "Thu", "Fri", "Sat", "Sun"];
                              for (var i = 0; i < a.length; ++i)
                                  append({name: a[i]})
                          }
                      }
                      Item {
                          width: (view.width) / 7
                          height: view.cellHeight
                          Rectangle {
                              color: "lightsteelblue"
                              anchors.fill: parent
                              anchors.rightMargin: 2
                              anchors.bottomMargin: 2
                          }
                          Text {
                              anchors.centerIn: parent
                              text: name
                          }
                      }
                  }
              }
          }
      }
      

      If this is intentional, it should be documented here and here.

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

            richard Richard Moe Gustavsen
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes