Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved] Delegate stops working when applying filter

    General and Desktop
    2
    3
    1536
    Loading More Posts
    • 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.
    • ?
      A Former User last edited by

      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 Reply Quote 0
      • G
        giesbert last edited by

        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 Reply Quote 0
        • ?
          A Former User last edited by

          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 Reply Quote 0
          • First post
            Last post