Results 1 to 4 of 4

Thread: A Question regarding QSortFilterProxyModel

  1. #1
    Join Date
    Dec 2011
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default A Question regarding QSortFilterProxyModel

    Hello guys!

    Whenever I retrieve a row from a QSqlTableModel the output on the view is naturally like this:
    ss1.png

    I would like to "customize" the way data is displayed like in the following image:

    Sans titre.png

    At first I had a wild idea of subclassing a QTableView but my guess is to manipulate the QModelIndexes and map them to new ones in the QSortFilterProxyModel but I'm not sure if this is the way to go, could you please help me on this one?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: A Question regarding QSortFilterProxyModel

    You could go for a QTreeView with a custom model (or use QSortFilterProxyModel) or provide a custom delegate, which fakes the view you like.

  3. #3
    Join Date
    Dec 2011
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: A Question regarding QSortFilterProxyModel

    This is very helpful thanks! I'll try to come up with a solution based off your suggestions

  4. #4
    Join Date
    Dec 2011
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: A Question regarding QSortFilterProxyModel

    Hello Again!

    Just wanted to give a quick update; I chose to implement a custom model, subclassing naturally QAbstractTableModel, and since it's read-only, I've had just four methods; rowcount, colmuncount, headerData, but the problem is with Data() method, here's what I did:

    Qt Code:
    1. QVariant CustomModel::data( const QModelIndex &index, int role ) const
    2. {
    3. QString name;
    4. QSqlQuery q("select name from employee where id=3");
    5. while (q.next()) {
    6. QVariant resultat = q.value(0);
    7. name = resultat.toString();
    8. }
    9.  
    10. switch( role )
    11. {
    12.  
    13. case Qt::DisplayRole:
    14.  
    15. if (index.column()==1 && index.row()==2)
    16. return name;
    17.  
    18. default:
    19.  
    20. return QVariant();
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    This works as I can display the data right where I want it to, but I'm not sure if this is the right way to go, any opinions?

    Thanks

Similar Threads

  1. Qsortfilterproxymodel
    By migel in forum Newbie
    Replies: 1
    Last Post: 3rd October 2011, 16:40
  2. Easy yes/no QSortFilterProxyModel question...
    By scott_hollen in forum Newbie
    Replies: 3
    Last Post: 14th March 2011, 17:11
  3. Using QSortFilterProxyModel
    By Jennie Bystrom in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2007, 10:28
  4. QSortFilterProxyModel
    By evgenM in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2007, 11:53

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.