2024-09-30 20:34:44 发布
网友
现在我正在使用self.setShowGrid(False),但它完全删除了网格线。所以不是全部就是什么都没有。但我只想要垂直的网格线,而不是像图中那样的水平网格线
这可能吗?如何做到这一点
一种可能的解决方案是使用代理绘制这些线:
from PyQt5 import QtCore, QtGui, QtWidgets class VerticalLineDelegate(QtWidgets.QStyledItemDelegate): def paint(self, painter, option, index): super(VerticalLineDelegate, self).paint(painter, option, index) line = QtCore.QLine(option.rect.topRight(), option.rect.bottomRight()) color = option.palette.color(QtGui.QPalette.Mid) painter.save() painter.setPen(QtGui.QPen(color)) painter.drawLine(line) painter.restore() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) w = QtWidgets.QTableWidget(10, 4) delegate = VerticalLineDelegate(w) w.setItemDelegate(delegate) w.setShowGrid(False) w.resize(640, 480) w.show() sys.exit(app.exec_())
一种可能的解决方案是使用代理绘制这些线:
相关问题 更多 >
编程相关推荐