Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PYQT4细胞颜色_Python_Pyqt4 - Fatal编程技术网

Python PYQT4细胞颜色

Python PYQT4细胞颜色,python,pyqt4,Python,Pyqt4,我正在尝试为单元格设置颜色 这是我的代码的一个小示例: self.tableWidget.setItem(1,8,QtGui.QTableWidgetItem("test)) # this works fine 我已经试过了 self.tableWidget.item(1,8,QtGui.QTableWidgetItem.setBackgroundColor("NOT SURE HERE")) # want cell to red 什么是使单元格颜色为红色且仍能看到单词“test”的最佳方法

我正在尝试为单元格设置颜色

这是我的代码的一个小示例:

self.tableWidget.setItem(1,8,QtGui.QTableWidgetItem("test)) # this works fine
我已经试过了

self.tableWidget.item(1,8,QtGui.QTableWidgetItem.setBackgroundColor("NOT SURE HERE")) # want cell to red

什么是使单元格颜色为红色且仍能看到单词“test”的最佳方法?实例化
QTableWidgetItem
并首先设置颜色:

item = QtGui.QTableWidgetItem("test")
item.setBackground(QtCore.Qt.red)
self.tableWidget.setItem(1,8,item)