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. How get delegates to move along when sorting a QTableView
Forum Updated to NodeBB v4.3 + New Features

How get delegates to move along when sorting a QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 428 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.
  • O Offline
    O Offline
    olowo726
    wrote on last edited by
    #1

    I have a setup where the delegate widget type, i.e. the one returned by createEditor in the delegate class, for column x in a QTableView depends on which row it is. I've implemented sorting in my model according to the pattering in https://doc.qt.io/qt-5/qabstractitemmodel.html#layoutChanged and also glanced on the QTableWidget source. It works fine for the values but the delegates doesn't move along, they're left in their old position. Hence I think that my calls to update persistent index,

    for (int i = 0; i < rowCount(); i++)
          {
             for (int c = 0; c < columnCount(); c++)
             {
                changePersistentIndex(createIndex(sortResult[i], c), createIndex(i, c));
             }
          }
    

    is correct. Anyone who knows what's required for the delegates to update their position? QStyledItemDelegate::updateEditorGeometry is called but option.rect is the same regardless of sorting. Not using QSortFilterProxyModel since the underying data should change at sorting.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      Use a QSortFilterProxyModel instead.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • O Offline
        O Offline
        olowo726
        wrote on last edited by
        #3

        Solved. For some reason one had to put the index updates in lists and use changePersistentIndexList().

        1 Reply Last reply
        0

        • Login

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