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. QAbstractTableModel C++ and tableView QML

QAbstractTableModel C++ and tableView QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
tableviewqabstractablevi
4 Posts 3 Posters 2.9k 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.
  • Lays147L Offline
    Lays147L Offline
    Lays147
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Lays147L 1 Reply Last reply
      0
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        Colums must be declared using TableViewColumn.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

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

          Lays147L Offline
          Lays147L Offline
          Lays147
          wrote on last edited by
          #4

          @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
          0

          • Login

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