0
如何更改pyside中QTreeWidgetItem的顏色?我想要一些是紅色的,一些是藍色的。我嘗試了各種各樣的東西,但我還沒有找到工作解決方案。希望有人能幫忙。 感謝pyside更改QTreeWidgetItem的顏色
# Modules
# ------------------------------------------------------------------------------
import sys
from PySide import QtGui, QtCore, QtSvg
# widget
# ------------------------------------------------------------------------------
class Example(QtGui.QWidget):
def __init__(self,):
super(Example, self).__init__()
self.initUI()
def initUI(self):
# formatting
self.setGeometry(300, 300, 250, 200)
self.setWindowTitle("Example")
# widgets
self.itemList = QtGui.QTreeWidget()
self.itemList.setItemsExpandable(True)
self.itemList.setAnimated(True)
self.itemList.setItemsExpandable(True)
self.itemList.setColumnCount(2)
self.itemList.setHeaderLabels(['', ''])
# add items
item0 = QtGui.QTreeWidgetItem(self.itemList, ['testing'])
item1 = QtGui.QTreeWidgetItem(self.itemList, ['testing'])
# add children
for i in xrange(0,4):
item00 = QtGui.QTreeWidgetItem(item0, ["Name"])
# layout
self.mainLayout = QtGui.QGridLayout(self)
self.mainLayout.addWidget(self.itemList)
self.show()
# Main
# ------------------------------------------------------------------------------
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())