gpt4 book ai didi

css - Qt Stylesheet 管理和性能

转载 作者:行者123 更新时间:2023-11-28 08:52:47 25 4
gpt4 key购买 nike

我对 Qt 样式表的管理有疑问。

我有一个大型 Qt 应用程序,可以动态更改其颜色主题。为此,我创建了几个样式表(一个按主题 - 它们非常大)。当用户想要更改颜色主题时,他单击调用 MainWindowQWidget 方法 setStylesheet(QString) 的按钮。这确实有效,但我的 GUI 在此过程中卡住了 8-10 秒。

为了减少延迟,我尝试使用unpolish(QApplication * application)QStyle::polish(QApplication * application)。性能令人印象深刻(不到一秒),但几个 Widget 属性没有更新,例如QToolButton 的图标属性。此外,我所有的自定义小部件都不会更新,即使它们继承自常见的小部件类(QFrameQwidgetQStackedWidget 等...)。我是否遗漏了 polish 方法的某些内容?有没有其他方法可以更好地更新我的应用程序的样式?

最佳答案

您可以使用 setPalette ( QPalette )

void QApplication::setPalette ( const QPalette & palette, const char * className = 0 ) [static]

Changes the default application palette to palette.

The palette may be changed according to the current GUI style in QStyle::polish().

Warning: Do not use this function in conjunction with Qt Style Sheets. When using style sheets, the palette of a widget can be customized using the "color", "background-color", "selection-color", "selection-background-color" and "alternate-background-color".

Note: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines.

如果你想从一个地方更改所有小部件的主题,这是个好方法。
我在大型应用程序中使用它并且运行良好。

但是,如果您将 styleSheet 或 palette 设置为小部件,则它不会获得您的一般主题。

QPalette myPalette;
myPalette.setColor(QPalette::Background, Qt::red);
myPalette.setColor(QPalette::WindowText, QColor(150, 150, 150));
qApp->setPalette(myPalette);

关于css - Qt Stylesheet 管理和性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27272493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com