2016-09-06 10:33:36 PyQT5 tableview 背景颜色
2016-09-06 10:33:36 PyQT5 tableview 背景颜色
from PyQt5.QtGui import *from PyQt5.Qt import *from PyQt5.QtCore import *class MyDialog(QDialog):def __init__(self, parent=None):super(MyDialog, self).__init__(parent)self.MyTable = QTableWidget(4,3)self.MyTable.setHorizontalHeaderLabels(['姓名','身高','体重'])newItem = QTableWidgetItem("松鼠")newItem.setBackground(QColor(120,130,150))self.MyTable.setItem(0, 0, newItem)newItem = QTableWidgetItem("10cm")newItem.setBackground(QColor('Lime'))self.MyTable.setItem(0, 1, newItem)newItem = QTableWidgetItem("60g")newItem.setBackground(QColor('Gray'))self.MyTable.setItem(0, 2, newItem)layout = QHBoxLayout()layout.addWidget(self.MyTable)self.setLayout(layout)if __name__ == '__main__':import sysapp = QApplication(sys.argv)myWindow = MyDialog()myWindow.show()sys.exit(app.exec_())

浙公网安备 33010602011771号