本页内容

QStyleFactory Class

QStyleFactory 类用于创建QStyle 对象。更多内容...

头文件: #include <QStyleFactory>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets

静态公共成员

QStyle *create(const QString &key)
QStringList keys()

详细说明

QStyle 类是一个抽象基类,用于封装GUI的外观和风格。QStyleFactory通过调用create()函数并传入一个标识样式的键,来创建QStyle 对象。这些样式可以是内置的,也可以从样式插件中动态加载(参见QStylePlugin )。

请使用keys()函数获取有效的键。内置样式(通常为“windows”和“fusion”)始终可用。 平台样式属于插件,仅在对应平台上可用:遵循 Windows 11 Fluent 设计的“windows11”,以及 Windows 系统上的“windowsvista”、macOS 系统上的“macos”和 Android 系统上的“android”。这些键不区分大小写。

另请参阅 QStyle 。

成员函数文档

[static] QStyle *QStyleFactory::create(const QString &key)

创建并返回一个与给定的key 匹配的QStyle 对象;如果未找到匹配的样式,则返回nullptr 。

系统会同时查询内置样式和样式插件中的样式,以查找匹配的样式。

注意:键 不区分大小写。

另请参阅 keys()。

[static] QStringList QStyleFactory::keys()

返回有效键的列表,即该工厂可以为其创建样式的键。

另请参阅 create()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.