【发布时间】:2020-12-18 11:07:11
【问题描述】:
我想从第一列标题中删除箭头,以便标题以复选框为中心。所有这些都不会禁用对列进行排序的可能性。
这是我当前的代码。
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (
QApplication,
QProxyStyle,
QStyle,
QTableWidget,
QTableWidgetItem,
)
class ProxyStyle(QProxyStyle):
def subElementRect(self, e, opt, widget):
r = super().subElementRect(e, opt, widget)
if e == QStyle.SE_ItemViewItemCheckIndicator:
r.moveCenter(opt.rect.center())
return r
class Table(QTableWidget):
def __init__(self):
QTableWidget.__init__(self, 3, 1)
self._style = ProxyStyle(self.style())
self.setStyle(self._style)
for i in range(self.rowCount()):
for j in range(self.columnCount()):
it = QTableWidgetItem()
self.setItem(i, j, it)
it.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
it.setCheckState(Qt.Checked if (i + j) % 2 == 0 else Qt.Unchecked)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Table()
w.show()
sys.exit(app.exec_())
【问题讨论】:
标签: python pyqt5 pyside2 qtablewidget