Real-time Sorting and Filtering of a GridView

From Qt Wiki
Revision as of 17:36, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

English Български

This wiki entry is created in response to a few forum threads (relevant link at bottom) asking for this method. Feel free to contribute to this article with explanations or code.

Real-time Sorting and Filtering of a GridView

I first generate a list of elements of various colours and shapes. After this, I create two text boxes for each variable (shape, colour).

In the latter section of code that deals with the GridView, I create a filter function which sifts through the elements in the model. I have hooked this function on to the onTextChanged event to create a real-time effect.

Having found an item that doesn’t match, it gets sent to the end of the list. If the item is matched, it is restored to its original index. The item will automatically fade away when it isn’t matched as the opacity property illustrates.

main.qml

Relevant forum thread: How to Assing an id property for dynamically created element. [developer.qt.nokia.com]

Categories: