Results 1 to 12 of 12

Thread: Proxymodel Sort , After Filter

  1. #1
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Proxymodel Sort , After Filter

    Hi ,

    I am using QSortfilterProxyModel , And when i filter on any column in QTableView , I am calling setFilterRegExp(QString) .

    The Filter working fine , But when i try to sort other column after filter the data dissappear, My thougt the sort working on other column with given filter text .
    But i want to sort filtered data in all columns .Help Me anyone .

  2. #2
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default How to Apply Filter On Multiple Columns

    Hi ,

    I need multi column filter functionality , Means , I am using QSortFilterProxyModel, Suppose I have 50 rows of data , And When I filter on 1st column I got 20 rows of data , and When I filter on other column The data will filter from 20 rows data . Is it possible , If possible , can any one post the sample code .

    Thanks

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    You can always try to derive from QSortFilterProxyModel and implement filterAcceptsRow()

    Cheers,
    _

  4. #4
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    You mean , can I customize QSortfilterproxymodel .

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    Exactly.

    Cheers,
    _

  6. #6
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    This is for MultiColumnFilter Right ?

    But , After Filter on any column , Can i sort on any other column on filtered data , is it possible , with out Customise QSortfilterProxyModel .
    Could you send any sample code for implement filterAcceptrows() function .


    Added after 16 minutes:


    I would like to do simple functionality using QSortFilterProxymodel , After filter on one column , i would like to sort on other column , but filtered text applied on sorting column .

    Means The data like below after filter i am filter with "xx" on A column
    Columns A B C

    XXA 100 SS
    XXB 120 QQ
    XXC 90 RR

    I applied filter on A Column , Now i would like to sort B ,column by clicking on B column ,

    I want data like

    A B
    XXC 90
    XXA 100

    But the XX filter also applied on B column when i sort , but i want only sort on B column . Could any one Help us .
    XXB 120
    Last edited by RameshNani; 19th December 2014 at 09:29.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    Show us your filterAcceptsRow() implementation.
    Maybe you are not checking the column of the index correctly.

    Cheers,
    _

  8. #8
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    Hi , Am facing the problem with how to start implementation of filterAcceptsRow() , means with out customize qsortfilterproxymodel , is it not possible to implement what ever we have to implement in filter accepts row ?
    My question is what code i would do in filteracceptrow() function , I would like to apply different filter on different columns , is it possible , if possible , could you please guide me with sample code , how to implement filteracceptsrow() , looks like the filteracceptsrow returns which ever rows satisfy current regular exp , but my point of view i would like to apply filter on one column , and i would like to apply different filter on different column with filtered data .

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    It is a function that gets a row index and returns a boolean.
    When it returns true the row of the given index is part of the result set, if it returns false the row will not show up.

    Your implementation can make that decision on whatever criteria you like.

    Qt Code:
    1. bool MySortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
    2. {
    3. return source_row % 2 == 1; // accept every second row
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  10. #10
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    I want to apply filter on some rows which are comes up from first Filter .
    So can I send all indexes to this filteracceptsrow function ?
    But , How can I identify which rows are having Previous filter ?

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    The function is already called for all rows, no need to do any calling yourself.

    In side that function you can decide if you want to accept the given row.
    How you determine that is of no concern to the proxy's base implementation.
    If you decide to use values from multiple columns then that is what you need to do.

    Alternatively, if your current level of C++ does not allow you to come up with code that compares multiple values in order, you could use a chain of proxies, each filtering on one criteria.

    Cheers,
    _

  12. #12
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Proxymodel Sort , After Filter

    Hi All,

    Thanks for your replies , My issue solved now. am implemented filteracceptsrow . thanking you for all .

Similar Threads

  1. Replies: 2
    Last Post: 10th September 2013, 10:37
  2. Replies: 0
    Last Post: 4th August 2013, 03:41
  3. TableView ProxyModel problem
    By poporacer in forum Newbie
    Replies: 11
    Last Post: 23rd August 2011, 04:08
  4. Replies: 19
    Last Post: 25th November 2010, 08:52
  5. ProxyModel problem
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2010, 06:40

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.