如何使用 StyleSheet 设置 qt widget 子属性

how set a qt widget subproperty with StyleSheet

我想使用 StyleSheet 设置 QT QDockWidget DockWidgetClosable 属性。 但是它在 'features' 属性.

里面

如何使用样式表更改它?

我试过了,没有成功。

比如。

QDockWidget{
    qproperty-floating:false; 
    qproperty-windowTitle:omg12;  
}

将参数 "floating" 和 "windowTitle" 设置为相应的值。但我还没有找到设置 "DockWidgetClosable" 值的键。

因为 QDockWidget 在 .qss 样式表中几乎被认为是 "class" - 如果您想修改所有 [=11= 的 DockWidgetClosable 属性 ] - 您必须像这样更改所有 QDockWidget 类 的值:

.QDockWidget{
    DockWidgetClosable: true;
}

解决方案

实际上您可以用样式 sheet 更改它,但不完全按照上面描述的那样。

我让它工作的唯一方法是直接调用 qproperty-feature 并将其值设置为一个字符串,该字符串包含我想使用的每个子功能的名称,并用竖线符号分隔它们.

例如:

QDockWidget{
   qproperty-features:"DockWidgetClosable | DockWidgetFloatable | DockWidgetVerticalTitleBar";
}

我在哪里找到这些信息?

遗憾的是没有直接可用的信息,但我在阅读在线文档时发现了一点提示:

在那里你可以找到枚举常量和相应值的 table。 table 个条目引起了我的注意:

Constant Value
QDockWidget::AllDockWidgetFeatures DockWidgetClosable|DockWidgetMovable|DockWidgetFloatable

从这个条目我得出结论,也许 qproperty-feature 的子功能可以通过它们的名字来设置,幸运的是它起作用了。