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. [Solved] Delegate stops working when applying filter
Forum Update on Monday, May 27th 2025

[Solved] Delegate stops working when applying filter

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 8 Mar 2012, 07:41 last edited by
    #1

    Hi guys:

    I've an already working model/view implementation using QAbstractTableModel, QStyledItemDelegate and a QTableView, so far so good. After this I needed to add a column filter, so I used QSortFilterProxyModel and here is when the problem arises. The filtering works fine but when the position of columns changes, the delegate stop working. I assume this happens because the column index has changed, so the delegate for the fifth column stops working because the fifth column is now the second. This is all about, right now I'm stuck.

    Any idea about how to solve this?

    Thanks in advance.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 8 Mar 2012, 07:55 last edited by
      #2

      This can not be answered in general.
      It highly depends on your delegate.

      If the delegate relies on the column number, then you might have a problem. You could check, whether the used model is a proxy and map the index to the source model index. But proxy models may be cascaded.

      You could also insert a custom data role and get that data from the model to check, how to behave as delegate (like MY_DATA_ROLE = UseRole + 1; MY_DATA_ROLE might return the original column index).

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on 11 Mar 2012, 23:41 last edited by
        #3

        You are right, as well as you thought my delegate relies on the column number.

        I already found a solution that solves my problem and on an easier way. This resides on change the delegate to relies on the column name (the columns name never changes) rather than their number.

        Thanks for your suggestions and your quick answer.

        1 Reply Last reply
        0

        1/3

        8 Mar 2012, 07:41

        • Login

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