[QSqlRelationalTableModel] problem with TreeView



  • 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.



  • 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.



  • 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 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.



  • [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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.