0

並べ替えやフィルタリングのために、QSortFilterProxyModelで拡張された関連モデルでテーブルビューを使用しています。行番号(つまり垂直ヘッダー)を除いて、すべて正常に機能します。このコードの使用:

def headerData(self, section, orientation, role):
    if role == QtCore.Qt.DisplayRole:
        if orientation == QtCore.Qt.Horizontal:
            return self.__header[section]
        elif orientation == QtCore.Qt.Vertical:
            return section + 1

各行には固定行番号が割り当てられています。そして、これはソート/フィルタリング時に問題を引き起こします。私は1つの解決策を考え出しました。デフォルトのフィルタリングと並べ替えの方法をオーバーライドし、いくつかの追加のパラメーター(行番号)をデータに入れて、並べ替えまたはフィルタリングのたびにそれを書き換えます。

質問:これに対する他の解決策はありますか?並べ替え/フィルタリング操作後に実際のアイテムの位置を表示する方法はありますか?

4

1 に答える 1

4

QSortFilterProxyModelwith customの単純なサブクラスはheaderDataそれを行います:

class MyProxy(QtGui.QSortFilterProxyModel):
    def headerData(self, section, orientation, role):
        # if display role of vertical headers
        if orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
            # return the actual row number
            return section + 1
        # for other cases, rely on the base implementation
        return super(MyProxy, self).headerData(section, orientation, role)
于 2013-02-27T13:11:51.227 に答える