Results 1 to 7 of 7

Thread: Issue with ProxyModel with tableview and VerticalHeader

  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Issue with ProxyModel with tableview and VerticalHeader

    Hi,
    Suppose using ProxyModel/Model/View.In tableView whenever the filtering occurs the numbering column(vertical Header) of tableview will filter too.
    I want to have sequence of proxymodel rows in numberingColumn(vertical header) instead of sourceModel when filtering occurs. see this:
    Unti121tled.png

    I've shown with red rectangle
    How can i do that?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Issue with ProxyModel with tableview and VerticalHeader

    Re-Implement QAbstractItemModel::headerData() in the proxy model, and make use of signal QAbstractItemModel::headerDataChanged(), when ever filtering / sorting is applied.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    alizadeh91 (15th April 2013)

  4. #3
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with ProxyModel with tableview and VerticalHeader

    Thanks Reddy for reply,
    What's the deal with headerData() ? I've thought that it must be setHeaderData??!!!
    Anyway, how can i do that in headerData method?

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Issue with ProxyModel with tableview and VerticalHeader

    A trivial implementation will look like
    Qt Code:
    1. class SortFilterProxyModel : public QSortFilterProxyModel
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit SortFilterProxyModel(QObject * parent = 0)
    6. {
    7. ;
    8. }
    9.  
    10. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
    11. {
    12. if((orientation == Qt::Vertical) and
    13. (role == Qt::DisplayRole) )
    14. return section + 1;
    15.  
    16. return sourceModel()->headerData(section, orientation, role); //<<<<<< TODO: Make sure sourceModel() is valid
    17. }
    18. };
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #5
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with ProxyModel with tableview and VerticalHeader

    Thanks, but i've already tired that! I think the default implementation of Qt is set to return section!

  7. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Issue with ProxyModel with tableview and VerticalHeader

    Thanks, but i've already tired that!
    Does that mean your problem is solved?

    I think the default implementation of Qt is set to return section!
    No, the default implementation of QSortFilterProxyModel::headerData() will return the section number from the source model. If you need to have continuous numbers even after applying filters, then you need to re-implement it.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. The following user says thank you to Santosh Reddy for this useful post:

    alizadeh91 (16th April 2013)

  9. #7
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with ProxyModel with tableview and VerticalHeader

    Thanks It works

Similar Threads

  1. Issue with custom delegate in tableview
    By alizadeh91 in forum Qt Programming
    Replies: 4
    Last Post: 13th April 2013, 08:39
  2. Replies: 1
    Last Post: 13th February 2012, 15:54
  3. TableView ProxyModel problem
    By poporacer in forum Newbie
    Replies: 11
    Last Post: 23rd August 2011, 04:08
  4. QT: editable tableview header issue.
    By raschko in forum Qt Programming
    Replies: 0
    Last Post: 27th February 2011, 19:15
  5. Verticalheader
    By iguanna in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 11:55

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.