Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QAbstractTableModel C++ and tableView QML

    QML and Qt Quick
    tableview qabstractablevi
    3
    4
    2522
    Loading More Posts
    • 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.
    • Lays147
      Lays147 last edited by

      Guys, morning!
      Im trying to put a QAbstractTableModel made in c++ in a view made with QML, but isnt drawing nothing in the view.
      This is my code:
      main.cpp

           fieldModel model;
          engine.rootContext()->setContextProperty("myModel",&model);
      
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      

      main.qml

      ApplicationWindow {
          visible: true
          title: qsTr("Naval Battle")
          color: "black"
      
          TableView{
                  id: _tableView
                  model: myModel
                  width: (Screen.width)/2
                  height: (Screen.height)/2
                  headerVisible: false
                  itemDelegate: Rectangle{
                              width: 40
                              height: 40
                              color: "blue"}
          }
      }
      

      Im reading the doc of TableView QML but, there only show how to draw a column, a row or a cell. Im thinking that the view will apply to all cells my itemDelegate property?

      Lays Rodrigues
      Newby on Qt - Learning always!
      Using QT 5.7
      ArchLinux

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Maybe a silly question but, is your model populated with something ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Lays147 1 Reply Last reply Reply Quote 0
        • jpnurmi
          jpnurmi last edited by

          Colums must be declared using TableViewColumn.

          1 Reply Last reply Reply Quote 0
          • Lays147
            Lays147 @SGaist last edited by

            @SGaist Yes. I managed to do using a Grid, since it was not possible to make the tableview. Now I have my view, but i was looking at the GridView doc, but dont know... if is better keep the current code or try something different.
            This is my actual qml code:

            import QtQuick 2.5
            import QtQuick.Controls 1.4
            import QtQuick.Window 2.2
            
            ApplicationWindow {
                visible: true
                width: Screen.width /2
                height: Screen.height /2
                Grid {
                    id : tabuleiro
                    columns: 10
                    rows: 10
                    anchors.fill: parent
                    spacing : 1
            
                    Repeater {
                        delegate : Rectangle {
                            width: Math.min(tabuleiro.width, tabuleiro.height) / 10
                            height: width
                            color : isWater ? "blue" : "red";
                        }
                        model : myModel;
                    }
                }
            }
            
            

            Lays Rodrigues
            Newby on Qt - Learning always!
            Using QT 5.7
            ArchLinux

            1 Reply Last reply Reply Quote 0
            • First post
              Last post