Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Indexes problem with QSortFIlterProxyModel and QStringListModel

Indexes problem with QSortFIlterProxyModel and QStringListModel

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 255 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • thaiboydigitalT Offline
    thaiboydigitalT Offline
    thaiboydigital
    wrote on last edited by
    #1

    Hello ,
    I have 4 objects :

    • QStringListModel
    • QSortFilterProxyModel
    • QListView
    • QStackedWidget

    So, QStackedWidget's current widget is changing with the current selection index in QListView. (So if i selected first element -> QStacketWidget will show first element).

    After, i need to add some filter features to QListView -> then i applied some RegExp with QSortFilterProxy, and set QListView's models - QSortFilterProxyModel. So it works fine, but the one moment that, after filtring, all accordings, like Index selection of QListView to QStackedWidget became wrong. :

    example :

    "ITEM 1" - 0
    "ITEM 2" - 1
    "ITEM 3" - 2

    assume like i find "ITEM 3" , after apply regexp, "ITEM 3" will become index 0(cause it's only one and first) in model , so the widget that would be shown is widget with index 0. and must be 3.

    "ITEM 3" - 0

    Can you give me an idea?

    So i have some thoughts about to make an one more column to QStringListModel that will be containing an original idx. is it good, or is there some better sollution ?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      just call QSortFilterProxyModel::mapToSource to convert a fitered index to the original one

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved