pyqt5 QTableWidget取消高亮,不可编辑,选中单元格颜色,改变单元格颜色

pyqt5 QTableWidget取消高亮,不可编辑,选中单元格颜色,改变单元格颜色

取消高亮(设置不可选中):self.QTableWidget.setSelectionMode(QAbstractItemView.NoSelection)

不可编辑:
self.QTableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)

设置选中单元格颜色(高亮颜色,故取消高亮后无效):
QTableWidget::item:selected{ background-color: rgb(255,255,255);} # 或#ffffff

改变单元格颜色:
self.QTableWidget.item(row, col).setBackground(QtGui.QColor(255, 255, 255))

获取单元格颜色;
self.QTableWidget.item(row, col).background().color().getRgb() # 返回的是int类型的数组(r,g,b) 如:(255,255,255)

你可能感兴趣的:(python,pyqt5)