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. DelegateChooser does not work
Forum Updated to NodeBB v4.3 + New Features

DelegateChooser does not work

Scheduled Pinned Locked Moved Solved QML and Qt Quick
delegatechoosertableview
2 Posts 2 Posters 1.4k 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by Dmitriano
    #1

    What is wrong in QML code below?

    import QtQuick.Controls 2.13
    import Qt.labs.qmlmodels 1.0
    
    //...
    
    TableView {
              anchors.fill: parent
              columnSpacing: 1
              rowSpacing: 1
              clip: true
    
              model: TableModel {}
    
              delegate: DelegateChooser {
                  role: "heading"
                  DelegateChoice {
                      roleValue: true
                      delegate: Text {
                          text: tabledata
                      }
                  }
                  DelegateChoice {
                      roleValue: false
                      delegate: Text {
                          text: tabledata
                      }
                  }
              }
          }
    

    When I start the app I get the following errors in the application output:

    TableView: failed loading index: 0
    TableView: failed loading index: 21
    TableView: failed loading index: 42
    TableView: failed loading index: 63
    TableView: failed loading index: 84
    TableView: failed loading index: 105
    TableView: failed loading index: 126
    ...
    

    What does this mean?

    There is the following delegate in the original example (that I cloned and modified):

    delegate: Rectangle {
                  implicitWidth: 150
                  implicitHeight: 50
                  border.color: "black"
                  border.width: 2
                  color: (heading==true)?"red":"green"
    
                  TableView.onPooled: console.log(tabledata + " pooled")
                  TableView.onReused: console.log(tabledata + " resused")
    
                  Text {
                      text: tabledata
                      font.pointSize: 12
                      anchors.centerIn: parent
                  }
              }
    

    that works fine, but if I replace it with my DelegateChooser the app stops working.

    My QT version is 5.13.

    ODБOïO 1 Reply Last reply
    0
    • D Dmitriano

      What is wrong in QML code below?

      import QtQuick.Controls 2.13
      import Qt.labs.qmlmodels 1.0
      
      //...
      
      TableView {
                anchors.fill: parent
                columnSpacing: 1
                rowSpacing: 1
                clip: true
      
                model: TableModel {}
      
                delegate: DelegateChooser {
                    role: "heading"
                    DelegateChoice {
                        roleValue: true
                        delegate: Text {
                            text: tabledata
                        }
                    }
                    DelegateChoice {
                        roleValue: false
                        delegate: Text {
                            text: tabledata
                        }
                    }
                }
            }
      

      When I start the app I get the following errors in the application output:

      TableView: failed loading index: 0
      TableView: failed loading index: 21
      TableView: failed loading index: 42
      TableView: failed loading index: 63
      TableView: failed loading index: 84
      TableView: failed loading index: 105
      TableView: failed loading index: 126
      ...
      

      What does this mean?

      There is the following delegate in the original example (that I cloned and modified):

      delegate: Rectangle {
                    implicitWidth: 150
                    implicitHeight: 50
                    border.color: "black"
                    border.width: 2
                    color: (heading==true)?"red":"green"
      
                    TableView.onPooled: console.log(tabledata + " pooled")
                    TableView.onReused: console.log(tabledata + " resused")
      
                    Text {
                        text: tabledata
                        font.pointSize: 12
                        anchors.centerIn: parent
                    }
                }
      

      that works fine, but if I replace it with my DelegateChooser the app stops working.

      My QT version is 5.13.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi @dmitriano

      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          TableView {
              anchors.fill: parent
              columnSpacing: 1
              rowSpacing: 1
              clip: true
              model: TableModel {}
              delegate: DelegateChooser {
                  role: "type"
                  DelegateChoice {        
                   roleValue: "lab2"     
                      delegate: Rectangle {
                          Text {
                              id: label2
                              text: "type delegate"
                          }
                      }
                  }
                  DelegateChoice {
                      // roleValue: "String" // default delegate
                      delegate: Rectangle {
                           color: ms.containsMouse ? "#d2cc01" : "lightgrey"
                          MouseArea{
                              anchors.fill: parent
                              hoverEnabled: true
                              id:ms
                          }
                          implicitWidth: defaultLabel.implicitWidth + 8
                          implicitHeight: defaultLabel.implicitHeight + 4
                          Text {
                              id: defaultLabel
                              text: tabledata
                          }
                      }
                  }
              }
          }
      }
      
      1 Reply Last reply
      2

      • Login

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