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. [QSqlRelationalTableModel] problem with TreeView
Forum Updated to NodeBB v4.3 + New Features

[QSqlRelationalTableModel] problem with TreeView

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 3.2k 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.
  • T Offline
    T Offline
    trex6
    wrote on last edited by
    #1

    Hi all.

    I have one little problem with my TreeModel, wich I inherited from QSqlRelationTableModel.
    Now I have reimplemented functions index(...), rowCount(...), parent(...) and data(...) and all this work well.
    But QTreeView doesn't show little triangle for expanding any string.
    Now I check my functions, but broblem isn't resoloved.

    I check any another variants and find: if rowCount return value>0, then QTreeView show this triangle. I check my function rowCount(...), i replace them with
    int TreeeModel::rowCount(...){return 2;}
    But TreeView doesn't show me triangle for expanding.

    Where is my mistake?

    P.S. I'm so sorry but my English is very bad.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      A table is a two-dimensional data structure (rows, columns), whereas a tree is a three-dimensional data structure (rows, columns, parent-child-relationship). See "here":http://doc.qt.nokia.com/latest/model-view-programming.html#basic-concepts.

      If you now apply a two-dimesional data structure (your QSqlRelationalTableModel) to a three-dimensional view (QTreeView) the third dimension ("little triangles") is lost.

      You will have to add a "QAbstractProxyModel":http://doc.qt.nokia.com/latest/qabstractproxymodel.html between your QSqlRelationalTableModel and your QTreeView which extracts the third-dimension-information (the "relation" in your case) from the database and maps it to a three-dimensional-model which is then used by your QTreeView.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        octal
        wrote on last edited by
        #3

        Just to say, one little tip to effectively debug your model is to use the "Model Test":http://developer.qt.nokia.com/wiki/Model_Test

        1 Reply Last reply
        0
        • T Offline
          T Offline
          trex6
          wrote on last edited by
          #4

          [quote author="Lukas Geyer" date="1314601900"]A table is a two-dimensional data structure (rows, columns), whereas a tree is a three-dimensional data structure (rows, columns, parent-child-relationship). See "here":http://doc.qt.nokia.com/latest/model-view-programming.html#
          <...>
          [/quote]

          Lukas Geyer, thank you for your answer.
          But now my model have three-dimension data structure for any view.
          [quote author="trex6" date="1314574119"]
          Now I have reimplemented functions index(...), rowCount(...), parent(...) and data(...) and all this work well.
          [/quote]
          My prent(..), rowCount(...), index(...) and data(...) functions set three-dimension model, QSqlRelationalTableModel used only for create internal data structures. All output data was created by my functions. And I testing them.

          In another way, any Model, inherited from QAbstractItemModel, with
          int rowCount(...){return 2;}
          show expanding triangles.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            trex6
            wrote on last edited by
            #5

            [quote author="octal" date="1314602195"]Just to say, one little tip to effectively debug your model is to use the "Model Test":http://developer.qt.nokia.com/wiki/Model_Test

            [/quote]

            octal, thank you for your answer.
            I will use this tonight. I hope, it will be helpfull for me.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              If your model only uses a QSqlRelationalTableModel, then I suggest you don't inherit from it, but instead use encapsulation. That is: your model has a QSqlrelationalTableModel, but is just a QAbstractItemModel.

              There is little we can say on why this happens, if you do not show us any relevant code.

              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