Reputation: 103
I am having trouble stylizing my tristate check boxes with children in my QtWidgets.QTreeWidget()
I am trying to use:
css ='''
QTreeView {background-color: #1e1e1e;}
QTreeView::indicator {border: 1px solid white;}
'''
self.file_tree.setStyleSheet(css)
The background color changes fine. But, once I add the solid border or try changing the background color of the checkbox the tristate checks are no longer visible. The old styles no longer apply. I do not have access or do not know how to access the QT resources as Maya has their own version with different images. i.e. the check box png.
Adding the parent directories of the tree with:
parent_widget = DirectoryTreeWidgetItem(parent_widget)
parent_widget.setText(0, self.base_name)
parent_widget.setFlags(parent_widget.flags() | QtCore.Qt.ItemIsTristate | QtCore.Qt.ItemIsUserCheckable)
Adding QTreeWidetItems through:
# add the items
for child_file in self.child_files:
# child = QtWidgets.QTreeWidgetItem(parent_widget)
child = AssetTreeWidgetItem(parent_widget)
child.setFlags(child.flags() | QtCore.Qt.ItemIsUserCheckable)
child.setText(0, os.path.basename(child_file))
child.setCheckState(0, QtCore.Qt.Unchecked)
child.setFilePath(child_file)
I am looking to change the border and/or the background color to make the boxes more visible rather than blending in with the dark background thee tree view.
Edit: I added color style sheet to designer and it also killed my checkbox. My goal is still the same make the checkbox more visible.
Upvotes: 1
Views: 1425
Reputation: 103
Since setStyleSheet
overrides the current style I was able to achieve the results I am looking for using QtGui.QPalette()
instead:
file_tree_palette = QtGui.QPalette()
file_tree_palette.setColor(QtGui.QPalette.Window, QtGui.QColor(255, 255, 255))
file_tree_palette.setColor(QtGui.QPalette.Base, QtGui.QColor(30, 30, 30))
file_tree_palette.setColor(QtGui.QPalette.Highlight, QtGui.QColor(93, 93, 93))
self.file_tree.setPalette(file_tree_palette)
I hope this can help someone who is working with style sheets.
Upvotes: 2