Results 1 to 9 of 9

Thread: Master/detail presentation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Master/detail presentation

    Happy new Year to everybody!
    Thanks a lot Numbat for your solution! It's exactly what I want obtain. But I've yet a question: I see in this example it is used some for loop and strings to fill the columns... how I can link the view to a gerarchical model? (I think to QSQLRelationalModel)
    By this, I'll have an indipendent widget that I can simply put on my form ad use it simply passing on it the model of my data.

    Thanks for your help!

    I'll show you, if you want how I'll use this.

    Michele

  2. #2
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Master/detail presentation

    Goodmorning to all.
    I'm working with the example of numbat (thanks a lot for this!) it's exaclty what I need!! But... working on it I've see this example use string constants to populate two level grid and all the sistem of "frozen column" is based over a single model.

    I've this problem now: I'd like to use this view with an SQL model. The most simple way is read all row and column of two QSqlTableModel (one for the first level and one for the second level) and set the strings into the treeview (using the tecnic showed by numbat), but i'd like to make something better.

    I'd like to create an SQL model then inglobe the two different Role and in which every item has different parent if need. I'd like to create ad QSqlTreeModel or something like this.

    I try to do this but my experience on QT is non enought and I loose myself.

    Does anybody any ideas of how can I create a model the can populate the grid? I thought to pass two tables and two fields to something like "select()" method of QSqlTableModel and use it as base... but I don't know which this cause.

    Have you got any ideas and some time to try to create it togheter?

    Thanks a lot for your time!

    Michele

  3. #3
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Master/detail presentation

    I've resolve the question adding a method that implements the code of the numbat's example:
    Qt Code:
    1. void HGrid::setMasterSlaveModel(QSqlTableModel *master, QSqlTableModel *slave, QString fieldmaster, QString fieldslave)
    2. {
    3. // Our master can have any number of columns.
    4. QStandardItem *parentItem = m->invisibleRootItem();
    5.  
    6. //Scorro il model principale per riga
    7. for (int i=0; i< master->rowCount();i++){
    8.  
    9. //Leggo il record corrente del model
    10. QSqlRecord rec = master->record(i);
    11. //Creo una lista di colonne
    12. QList<QStandardItem*> colsFatt;
    13.  
    14. //Scorro tutte le colonne
    15. for (int j=0; j<master->columnCount();++j){
    16.  
    17. //Aggiungo i dati delle colonne alla lista
    18. colsFatt.push_back(new QStandardItem(rec.value(j).toString()));
    19. }
    20.  
    21. //Aggiungo la lista dei dati delle colonne al model
    22. parentItem->appendRow(colsFatt);
    23.  
    24. //Creo un elemento fittizio per aggiungere i dati di secondo livello
    25. QStandardItem * ph = new QStandardItem( "Placeholder");
    26. colsFatt.at(0)->appendRow(ph);
    27. ph->setFlags(Qt::NoItemFlags);
    28.  
    29. slave->setFilter(QString("%1=%2").arg(fieldslave).arg(rec.value(fieldmaster).toInt()));
    30. for (int k = 0; k < slave->rowCount(); k++)
    31. {
    32. QList<QStandardItem*> colsDett;
    33. QSqlRecord recDett = slave->record(k);
    34. for (int x = 0; x < slave->columnCount(); ++x)
    35. {
    36. colsDett.push_back(new QStandardItem(recDett.value(x).toString()));
    37. }
    38. m2->invisibleRootItem()->appendRow(colsDett);
    39. }
    40. m->setData(ph->index(), QVariant(QMetaType::type("QAbstractItemModel*"), &m2), ChildModelRole);
    41. }
    42.  
    43. this->setModel(m);
    44. }
    To copy to clipboard, switch view to plain text mode 

    But I don't like it so much. Is there any smarter solution? Have you got any ideas?

    Thanks a lot for your time.

    Michele

  4. #4
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Master/detail presentation

    And, with this structure, how can I show images on the first column (of both the QTreeView). One image for the items of firts level (first QTreeview) and an other for the items of internal QTreeview (second level).

    Have you got any idea?

    Thank a lot for your time

    Michele

Similar Threads

  1. Widget for chat presentation
    By krivenok in forum Qt Programming
    Replies: 8
    Last Post: 24th January 2006, 13:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.