Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. display text in tableviewcolumn in treeView QtQuick controls 1.4
Forum Updated to NodeBB v4.3 + New Features

display text in tableviewcolumn in treeView QtQuick controls 1.4

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 649 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.
  • M Offline
    M Offline
    mohy
    wrote on last edited by
    #1

    Hi all,

    Im trying to create a simple treeView appeared in Qt 5.5 , the problem is that the text in items of the tree doesn't display, despite the model is full.

    There is my code :

    TreeViewPM.qml

    Qt Code:
    Switch view

    import QtQuick 2.2
    import QtQuick.Controls 1.4
    import QtQml.Models 2.2
    import KMTreeModelPM 1.0
     
    Item {
     
        KMTreeModelPM {
            id: treeModel
        }
     
        ItemSelectionModel {
            id: sel
            model: treeModel
        }
        Text {
            id:txt
            text: " "
        }
     
     
        TreeView {
            id: view
            anchors.fill: parent
            anchors.margins:  12
            selection: sel
            headerVisible : false
            itemDelegate: Rectangle {
                       color: ( styleData.row % 2 == 0 ) ? "white" : "lightblue"
                       height: 20
     
                       Text {
                           anchors.verticalCenter: parent.verticalCenter
                           anchors.left: parent.left // by default x is set to 0 so this had no effect
                           text: styleData.value
                       }
                   }
            TableViewColumn {
                id : title
                title: "Title"
                role: "title"
                resizable: true
                horizontalAlignment : Text.AlignLeft
            }
            model: treeModel
     
            onDoubleClicked: txt.text = treeModel.data(index,0) 
     
        }
     
    }
    

    To copy to clipboard, switch view to plain text mode

    main.qml

    Qt Code:
    Switch view

    import QtQuick 2.2
    import QtQuick.Controls 1.4
    import QtQml.Models 2.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls.Styles 1.4
     
    Rectangle {
        width: 785
            TabView {
                x: 17
                y: 8
                width: 970
                height: 800
                currentIndex: 2
                visible: true
                Tab {
                    id: tabAddProfile
                    title: qsTr("Add Profile")
                    AddProfilePage{}
                }
                Tab {
                    id: tabAddTypeSubType
                    title: qsTr("Add Type/SubType")
                    AddTypeSubTypePage{}
                }
                Tab {
                    id: tabAddDetail
                    height: 413
                    visible: true
                    title: qsTr("Add Detail")
                    TreeViewPM {}
                }
     
            }
     
        }
    
    p3c0P 1 Reply Last reply
    0
    • M mohy

      Hi all,

      Im trying to create a simple treeView appeared in Qt 5.5 , the problem is that the text in items of the tree doesn't display, despite the model is full.

      There is my code :

      TreeViewPM.qml

      Qt Code:
      Switch view

      import QtQuick 2.2
      import QtQuick.Controls 1.4
      import QtQml.Models 2.2
      import KMTreeModelPM 1.0
       
      Item {
       
          KMTreeModelPM {
              id: treeModel
          }
       
          ItemSelectionModel {
              id: sel
              model: treeModel
          }
          Text {
              id:txt
              text: " "
          }
       
       
          TreeView {
              id: view
              anchors.fill: parent
              anchors.margins:  12
              selection: sel
              headerVisible : false
              itemDelegate: Rectangle {
                         color: ( styleData.row % 2 == 0 ) ? "white" : "lightblue"
                         height: 20
       
                         Text {
                             anchors.verticalCenter: parent.verticalCenter
                             anchors.left: parent.left // by default x is set to 0 so this had no effect
                             text: styleData.value
                         }
                     }
              TableViewColumn {
                  id : title
                  title: "Title"
                  role: "title"
                  resizable: true
                  horizontalAlignment : Text.AlignLeft
              }
              model: treeModel
       
              onDoubleClicked: txt.text = treeModel.data(index,0) 
       
          }
       
      }
      

      To copy to clipboard, switch view to plain text mode

      main.qml

      Qt Code:
      Switch view

      import QtQuick 2.2
      import QtQuick.Controls 1.4
      import QtQml.Models 2.2
      import QtQuick.Layouts 1.1
      import QtQuick.Controls.Styles 1.4
       
      Rectangle {
          width: 785
              TabView {
                  x: 17
                  y: 8
                  width: 970
                  height: 800
                  currentIndex: 2
                  visible: true
                  Tab {
                      id: tabAddProfile
                      title: qsTr("Add Profile")
                      AddProfilePage{}
                  }
                  Tab {
                      id: tabAddTypeSubType
                      title: qsTr("Add Type/SubType")
                      AddTypeSubTypePage{}
                  }
                  Tab {
                      id: tabAddDetail
                      height: 413
                      visible: true
                      title: qsTr("Add Detail")
                      TreeViewPM {}
                  }
       
              }
       
          }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @mohy
      Is KMTreeModelPM a C++ model ? Can you share its code ?

      157

      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