【问题标题】:Change the style of a checkbox in a QTreeWidget without affecting the check marks in Maya?更改 QTreeWidget 中复选框的样式而不影响 Maya 中的复选标记?
【发布时间】: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)

我希望更改边框和/或背景颜色以使框更可见,而不是与树视图的深色背景混合。

编辑:我向设计师添加了颜色样式表,它也杀死了我的复选框。我的目标仍然是使复选框更加明显。

【问题讨论】:

    标签: python pyqt5 maya


    【解决方案1】:

    由于setStyleSheet 覆盖了当前样式,我能够使用QtGui.QPalette() 来实现我正在寻找的结果:

        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)
    

    我希望这可以帮助正在使用样式表的人。

    【讨论】:

      猜你喜欢
      • 2019-11-12
      • 1970-01-01
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      相关资源
      最近更新 更多