QStyleHintReturn Class
QStyleHintReturn 类提供了能够返回基本数据类型以外内容的样式提示。更多内容...
| 头文件: | #include <QStyleHintReturn> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 由以下工具继承: |
公共类型
| enum | HintReturnType { SH_Default, SH_Mask, SH_Variant } |
| enum | StyleOptionType { Type } |
| enum | StyleOptionVersion { Version } |
公共函数
| QStyleHintReturn(int version = QStyleOption::Version, int type = SH_Default) |
公共变量
相关的非成员
| T | qstyleoption_cast(const QStyleHintReturn *hint) |
| T | qstyleoption_cast(QStyleHintReturn *hint) |
详细说明
QStyleHintReturn 及其子类用于将信息从样式传递回查询的小部件。当QStyle::styleHint() 的返回值无法提供足够详细的信息时,此功能最为有用;例如,当需要返回一个掩码时。
成员类型文档
enum QStyleHintReturn::HintReturnType
| 常数 | 值 | 描述 |
|---|---|---|
QStyleHintReturn::SH_Default | 0xf000 | QStyleHintReturn |
QStyleHintReturn::SH_Mask | 0xf001 | QStyle::SH_RubberBand_Mask QStyle::SH_FocusFrame_Mask |
QStyleHintReturn::SH_Variant | 0xf002 | QStyle::SH_TextControl_FocusIndicatorTextCharFormat |
enum QStyleHintReturn::StyleOptionType
该枚举用于存储样式选项类型的相关信息,并针对每个QStyleHintReturn 子类分别定义。
| 常量 | 常量值 | 描述 |
|---|---|---|
QStyleHintReturn::Type | SH_Default | 提供的样式选项的类型(对于此类而言为SH_Default )。 |
该类型由QStyleHintReturn 、其子类以及qstyleoption_cast()在内部使用,以确定样式选项的类型。通常情况下,除非您想创建自己的QStyleHintReturn 子类和自己的样式,否则无需担心这一点。
另请参阅 StyleOptionVersion 。
enum QStyleHintReturn::StyleOptionVersion
该枚举用于存储样式选项的版本信息,并针对每个QStyleHintReturn 子类分别定义。
| 常量 | 常量值 | 描述 |
|---|---|---|
QStyleHintReturn::Version | 1 | 1 |
QStyleHintReturn 的子类使用该版本号来实现扩展,同时保持兼容性。如果您使用qstyleoption_cast(),通常无需检查该值。
另请参阅 StyleOptionType 。
成员函数文档
QStyleHintReturn::QStyleHintReturn(int version = QStyleOption::Version, int type = SH_Default)
构建一个版本为version 、类型为type 的QStyleHintReturn。
对于 QStyleHintReturn 而言,该版本号没有特殊含义;子类可以使用它来区分同一提示类型的不同版本。
成员变量文档
int QStyleHintReturn::type
该变量存储样式提示容器的类型
另请参阅 HintReturnType 。
int QStyleHintReturn::version
该变量存储样式提示返回容器的版本号
子类可以使用此值来实现扩展,同时保持兼容性。如果您使用qstyleoption_cast<T>(),通常无需检查此值。
相关的非成员
template <typename T> T qstyleoption_cast(const QStyleHintReturn *hint)
根据hint 的type 和version ,返回 T 或nullptr 。
示例:
int MyStyle::styleHint(StyleHint stylehint, const QStyleOption *opt,
const QWidget *widget, QStyleHintReturn* returnData) const;
{
if (stylehint == SH_RubberBand_Mask) {
const QStyleHintReturnMask *maskReturn =
qstyleoption_cast<const QStyleHintReturnMask *>(hint);
if (maskReturn) {
...
}
}
...
}另请参阅 QStyleHintReturn::type 和QStyleHintReturn::version 。
template <typename T> T qstyleoption_cast(QStyleHintReturn *hint)
根据hint 的类型,返回T或nullptr 。
这是一个重载函数。
© 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.