Issue
How can I change the color of a QTreeWidgetItem in pyside? I want some to be red and some to be blue. I've tried various things and i haven't found a working solution yet. Hope someone can help. Thanks
# 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_())
Solution
item1.setForeground(0,QtGui.QBrush(QtGui.QColor("red")))
Answered By - JokerMartini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.