【发布时间】:2019-02-13 07:21:01
【问题描述】:
我无法在 QtWidgets.QTreeWidget() 中设置带有子项的三态复选框
我正在尝试使用:
css ='''
QTreeView {background-color: #1e1e1e;}
QTreeView::indicator {border: 1px solid white;}
'''
self.file_tree.setStyleSheet(css)
背景颜色变化很好。但是,一旦我添加了实心边框或尝试更改复选框的背景颜色,三态检查将不再可见。旧样式不再适用。我无权访问或不知道如何访问 QT 资源,因为 Maya 有自己的版本和不同的图像。即复选框png。
添加树的父目录:
parent_widget = DirectoryTreeWidgetItem(parent_widget)
parent_widget.setText(0, self.base_name)
parent_widget.setFlags(parent_widget.flags() | QtCore.Qt.ItemIsTristate | QtCore.Qt.ItemIsUserCheckable)
通过以下方式添加 QTreeWidetItems:
# 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)
我希望更改边框和/或背景颜色以使框更可见,而不是与树视图的深色背景混合。
编辑:我向设计师添加了颜色样式表,它也杀死了我的复选框。我的目标仍然是使复选框更加明显。
【问题讨论】: