【问题标题】:How to control sorting arrow indicator on QTableView如何控制 QTableView 上的排序箭头指示器
【发布时间】:2023-03-04 12:37:01
【问题描述】:

创建此QTableView 时,我希望显示排序“箭头”指示符 在中间的柱子上。箭头需要指向下方。如何做到这一点?

from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])

class Model(QtCore.QAbstractTableModel):
    def __init__(self):
        QtCore.QAbstractTableModel.__init__(self)
        self.items = [[1, 'one', 'ONE'], [2, 'two', 'TWO'], [3, 'three', 'THREE']]

    def rowCount(self, parent=QtCore.QModelIndex()):
        return 3 
    def columnCount(self, parent=QtCore.QModelIndex()):
        return 3

    def data(self, index, role):
        if not index.isValid(): return 

        if role == QtCore.Qt.DisplayRole:
            return self.items[index.row()][index.column()]

tableModel=Model()
tableView=QtGui.QTableView() 
tableView.setModel(tableModel)
tableView.setSortingEnabled(True)

tableView.show()
app.exec_()

【问题讨论】:

    标签: python qt pyqt qtableview qabstracttablemodel


    【解决方案1】:

    你必须使用sortByColumn函数,使用Descending Order使箭头“指向下方”:

    tableView.sortByColumn(1, QtCore.Qt.DescendingOrder)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 2023-03-31
      相关资源
      最近更新 更多