Results 1 to 10 of 10

Thread: FilterProxy model

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: FilterProxy model

    If you reimplement filterAcceptRows you can do any filtering you want. You get an index of the model, you do whatever you want with it and then return true or false to make the index visible or not. For example once I made a filter that filtered rows based on results of some heavy calculations performed on the whole model. The threshold value was set by a slider that was connected to the proxy model so whenever the slider value changed, the filter was recalculated.

  2. #2
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: FilterProxy model

    thanks guys...Ill try to implement it as you advised me...
    just one last question...
    Is there such thing(method) that would allow me to disable/enable filtering upon some event ? like when the state of checkbox changes ...

    I thought I understood invalidateFilter() method but it seems I dont...what does it do ?
    Thanks

  3. #3
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: FilterProxy model

    Since you are using a custom proxy model, you probably dont use the setFilterRegExp, setFilterFixedString, etc. methods, to pass a single string as filtering criterion.
    The above functions (if i understood correctly) do call invalidateFilter themselves, when they are called.
    So you have to use invalidateFilter yourself after setting the new filtering criterias; you are basically forcing the model to consider your updated criterias instead the old ones.

    You can enable/disable using the filter, if thats what you meant by that, by for instance setting a flag in your model, when the checkbox is checked, then in filterAcceptsRow if this flag is checked, you use the filter, if not, you just return true, thus every row is accepted.
    Don't forget calling invalidateFilter after you set the flag.

    Hope it helps.

  4. #4
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: FilterProxy model

    I dont know...I tried to implement the model as show in example but it somehow doesnt work...Can anyone tell me why not ? ...
    I attached the header and source files Im using...
    Thanks
    Attached Files Attached Files
    Last edited by gyre; 4th December 2007 at 14:02. Reason: updated contents

  5. #5
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: FilterProxy model

    I changed the files to ones that are in attachements...
    Filtering now works OK...but when I remove all characters from lineedit from which I control filtering the model does not get to the original state and ALL items are filtered...dont know why
    Attached Files Attached Files

  6. #6
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: FilterProxy model

    I have found a problem...it has to be checked whether the regexps are empty...
    see the attached code if youre interested...
    Attached Files Attached Files

Similar Threads

  1. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 17:31
  2. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  3. Coin3d + Qt: SIGLNALs and SLOTs
    By vonCZ in forum Newbie
    Replies: 26
    Last Post: 15th May 2009, 07:34
  4. Help with Model View
    By weepdoo in forum Qt Programming
    Replies: 13
    Last Post: 12th October 2007, 10:32
  5. Model Choices review/questions
    By ucntcme in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2007, 21:57

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.