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 TableView not showing
Qt 6.11 is out! See what's new in the release blog

QML TableView not showing

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

    I refer to the documentation https://doc.qt.io/qt-6/qml-qtquick-controls-verticalheaderview.html and try to show a table view in QML:

    import QtQuick
    import QtQuick.Controls
    
    Dialog {
        id: devTableDialog
        width: 800
        height: 600
        anchors.centerIn: parent
        modal: true
        standardButtons: Dialog.Ok
    
        contentItem: Item {
            implicitWidth: parent.width
            implicitHeight: parent.height
    
            VerticalHeaderView {
                id: verticalHeader
                anchors.top: devTView.top
                anchors.left: parent.left
                syncView: devTView
                clip: true
            }
    
            TableView {
                id: devTView
                anchors.left: verticalHeader.right
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                clip: true
    
                columnSpacing: 1
                rowSpacing: 1
    
                model: device
    
                delegate: Rectangle {
                    implicitWidth: 100
                    implicitHeight: 50
                    color: palette.base  // border.color: "black"
    
                    Text {
                        text: model.display
                        anchors.centerIn: parent
                    }
                }
            }
        }
    }
    

    When I open the dialog, it shows nothing; however, if I write

    import QtQuick
    import QtQuick.Controls
    
    Dialog {
        id: devTableDialog
        width: 800
        height: 600
        anchors.centerIn: parent
        modal: true
        standardButtons: Dialog.Ok
    
        contentItem: TableView {
                id: devTView
                anchors.left: verticalHeader.right
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                clip: true
    
                columnSpacing: 1
                rowSpacing: 1
    
                model: device
    
                delegate: Rectangle {
                    implicitWidth: 100
                    implicitHeight: 50
                    color: palette.base  // border.color: "black"
    
                    Text {
                        text: model.display
                        anchors.centerIn: parent
                    }
                }
        }
    }
    

    Then, the dialog can properly show the table view. I wonder how to show the table view together with the VerticalHeaderView in the contentItem? Thanks.

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      Yihua Liu
      wrote on last edited by
      #3

      Problem fixed by setting anchors

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Yihua Liu
        wrote on last edited by
        #2

        The second code snippet above has problem. The correct code snippet is

        import QtQuick
        import QtQuick.Controls
        
        Dialog {
            id: devTableDialog
            width: 800
            height: 600
            anchors.centerIn: parent
            modal: true
            standardButtons: Dialog.Ok
        
            contentItem: TableView {
                    id: devTView
                    implicitWidth: parent.width
                    implicitHeight: parent.height
                    clip: true
        
                    columnSpacing: 1
                    rowSpacing: 1
        
                    model: device
        
                    delegate: Rectangle {
                        implicitWidth: 100
                        implicitHeight: 50
                        color: palette.base
        
                        Text {
                            text: model.display
                            anchors.centerIn: parent
                        }
                    }
            }
        }
        
        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          Yihua Liu
          wrote on last edited by
          #3

          Problem fixed by setting anchors

          1 Reply Last reply
          0
          • Y Yihua Liu has marked this topic as solved on

          • Login

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