QStyleHints Class
QStyleHints 类包含平台特定的提示和设置。更多
Header: | #include <QStyleHints> |
CMake.QStyleHints | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QObject |
属性
|
|
公共功能
信号
void | colorSchemeChanged(Qt::ColorScheme colorScheme) |
void | contextMenuTriggerChanged(Qt::ContextMenuTrigger contextMenuTrigger) |
void | cursorFlashTimeChanged(int cursorFlashTime) |
void | keyboardInputIntervalChanged(int keyboardInputInterval) |
void | mouseDoubleClickIntervalChanged(int mouseDoubleClickInterval) |
void | mousePressAndHoldIntervalChanged(int mousePressAndHoldInterval) |
void | mouseQuickSelectionThresholdChanged(int threshold) |
void | showShortcutsInContextMenusChanged(bool) |
void | startDragDistanceChanged(int startDragDistance) |
void | startDragTimeChanged(int startDragTime) |
void | tabFocusBehaviorChanged(Qt::TabFocusBehavior tabFocusBehavior) |
void | useHoverEffectsChanged(bool useHoverEffects) |
void | wheelScrollLinesChanged(int scrollLines) |
详细说明
从QGuiApplication 获取的该类对象可访问当前平台的某些全局用户界面参数。
对大多数设置的访问都是只读的。平台本身通常会为用户提供调整这些参数的方法。自定义用户界面组件的作者应读取相关设置,以使组件表现出与其他组件相同的行为和感觉。
另请参阅 QGuiApplication::styleHints()。
属性文档
[since 6.5]
colorScheme : Qt::ColorScheme
该属性用于保存应用程序使用的配色方案。
默认情况下,它遵循系统的默认配色方案(也称为外观),并在系统配色方案发生变化时(如黄昏或黎明时分)进行更改。将配色方案设置为明确值将覆盖系统设置,并忽略系统配色方案的任何变化。不过,这样做会给系统带来提示,而且并非所有平台都支持覆盖配色方案。
重置该属性,或将其设置为Qt::ColorScheme::Unknown ,将取消覆盖,使应用程序重新遵循系统默认设置。属性值将更改为系统当前的配色方案。
当该属性发生变化时,Qt 将读取系统调色板并更新默认调色板,但不会覆盖应用程序显式设置的调色板条目。当 colorSchemeChange() 信号发出时,旧的调色板仍然有效。
应在考虑到当前配色方案的情况下,选择与应用程序特定的颜色,以便与有效的调色板配合使用。要在有效调色板发生变化时更新特定于应用程序的颜色,可处理PaletteChange 或ApplicationPaletteChange 事件。
此属性在 Qt 6.5 中引入。
访问功能:
Qt::ColorScheme | colorScheme() const |
void | setColorScheme(Qt::ColorScheme scheme) |
void | unsetColorScheme() |
Notifier 信号:
void | colorSchemeChanged(Qt::ColorScheme colorScheme) |
另请参见 Qt::ColorScheme 、QGuiApplication::palette() 和QEvent::PaletteChange 。
[since 6.8]
contextMenuTrigger : Qt::ContextMenuTrigger
用于触发上下文菜单事件的鼠标事件。
在 UNIX 系统中,默认情况下是在按下鼠标键事件中显示上下文菜单,而在 Windows 系统中则是在释放鼠标键事件中显示上下文菜单。该属性可用于覆盖默认的平台行为。
注意: 开发人员在使用该属性时必须非常谨慎,因为它会改变用户在其运行平台上所期望的默认交互模式。
此属性在 Qt 6.8 中引入。
访问函数:
Qt::ContextMenuTrigger | contextMenuTrigger() const |
void | setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger) |
Notifier 信号:
void | contextMenuTriggerChanged(Qt::ContextMenuTrigger contextMenuTrigger) |
另请参阅 Qt::ContextMenuTrigger 。
[read-only]
cursorFlashTime : const int
该属性用于保存文本光标的闪烁(闪烁)时间,单位为毫秒。
闪烁时间是用于显示、反转和恢复光标显示的时间。通常情况下,文本光标显示时间为光标闪烁时间的一半,然后在相同的时间内隐藏。
访问功能:
int | cursorFlashTime() const |
通知信号:
void | cursorFlashTimeChanged(int cursorFlashTime) |
[read-only]
fontSmoothingGamma : const qreal
该属性用于保存字体平滑时使用的伽玛值。
访问功能:
qreal | fontSmoothingGamma() const |
[read-only, since 6.5]
keyboardAutoRepeatRateF : const qreal
该属性以每秒事件数为单位,表示在按住一个键的情况下,自动产生额外重复按键的速率。
该属性在 Qt 6.5 中引入。
访问函数:
qreal | keyboardAutoRepeatRateF() const |
[read-only]
keyboardInputInterval : const int
该属性以毫秒为单位,用于区分一次按键和连续两次按键。
访问功能:
int | keyboardInputInterval() const |
通知信号:
void | keyboardInputIntervalChanged(int keyboardInputInterval) |
[read-only]
mouseDoubleClickDistance : const int
该属性以像素为单位保存了鼠标在连续两次点击之间移动并仍能被检测为双击的最大距离。
访问功能:
int | mouseDoubleClickDistance() const |
[read-only]
mouseDoubleClickInterval : const int
该属性保存了区分双击和连续两次鼠标点击的时间限制(毫秒)。
访问功能:
int | mouseDoubleClickInterval() const |
Notifier 信号:
void | mouseDoubleClickIntervalChanged(int mouseDoubleClickInterval) |
[read-only]
mousePressAndHoldInterval : const int
该属性用于保存激活按住的时间限制(以毫秒为单位)。
访问功能:
int | mousePressAndHoldInterval() const |
通知信号:
void | mousePressAndHoldIntervalChanged(int mousePressAndHoldInterval) |
mouseQuickSelectionThreshold : const int
快速选择鼠标阈值,单位为QLineEdit 。
该属性定义了在正常的QLineEdit 文本选择过程中,鼠标光标应沿 Y 轴移动多少才会触发快速选择。
如果属性值小于或等于 0,则禁用快速选择功能。
访问功能:
int | mouseQuickSelectionThreshold() const |
通知信号:
void | mouseQuickSelectionThresholdChanged(int threshold) |
[read-only]
passwordMaskCharacter : const QChar
该属性包含用于屏蔽密码模式下文本输入字段中输入的字符的字符。
访问功能:
QChar | passwordMaskCharacter() const |
[read-only]
passwordMaskDelay : const int
该属性用于保存在密码模式下文本输入框中以毫秒为单位显示已输入字母的时间。
访问功能:
int | passwordMaskDelay() const |
[read-only]
setFocusOnTouchRelease : const bool
该属性用于保存为焦点对象设置输入焦点的事件。
如果焦点对象(行编辑等)应在触摸/鼠标释放后接收输入焦点,则该属性为true
。这是触摸平台上的正常行为。在桌面平台上,标准做法是在触摸/鼠标按下时已设置焦点。
访问功能:
bool | setFocusOnTouchRelease() const |
[read-only]
showIsFullScreen : const bool
该属性表示平台是否默认为全屏窗口。
如果平台默认为全屏窗口,则此属性为true
,否则为false
。
注: 平台仍可选择显示某些非全屏窗口,如弹出窗口或对话框。此属性仅报告默认行为。
访问功能:
bool | showIsFullScreen() const |
另请参阅 QWindow::show() 和showIsMaximized()。
[read-only]
showIsMaximized : const bool
该属性表示平台是否默认最大化窗口。
如果平台默认窗口最大化,则该属性为true
,否则为false
。
注意: 平台仍可选择以非最大化方式显示某些窗口,如弹出窗口或对话框。此属性仅报告默认行为。
访问功能:
bool | showIsMaximized() const |
另请参阅 QWindow::show() 和showIsFullScreen()。
showShortcutsInContextMenus : bool
true
如果平台通常在上下文菜单中显示快捷键序列,则 。false
自 Qt 5.13 起,可使用 setShowShortcutsInContextMenus() 函数覆盖平台默认值。
访问函数:
bool | showShortcutsInContextMenus() const |
void | setShowShortcutsInContextMenus(bool showShortcutsInContextMenus) |
Notifier 信号:
void | showShortcutsInContextMenusChanged(bool) |
另请参见 Qt::AA_DontShowShortcutsInContextMenus 。
[read-only]
singleClickActivation : const bool
该属性表示项目是通过单击还是双击激活的。
如果项目应通过单击激活,则该属性为true
;如果应通过双击激活,则该属性为false
。
访问功能:
bool | singleClickActivation() const |
[read-only]
startDragDistance : const int
该属性保存了在拖放操作开始前,按住按钮移动鼠标的距离(以像素为单位)。
如果您的应用程序支持拖放,并希望在用户按住按钮将光标移动一定距离后开始拖放操作,则应使用此属性的值作为所需的最小距离。
例如,如果单击时的鼠标位置存储在startPos
中,而当前位置(如鼠标移动事件中的位置)为currentPos
,则可通过以下代码了解是否应启动拖放操作:
if ((startPos - currentPos).manhattanLength() >= QApplication::startDragDistance()) startTheDrag();
访问功能:
int | startDragDistance() const |
Notifier 信号:
void | startDragDistanceChanged(int startDragDistance) |
另请参阅 startDragTime 、QPoint::manhattanLength() 以及拖放。
[read-only]
startDragTime : const int
该属性用于保存拖放操作开始前必须按住鼠标键的时间(以毫秒为单位)。
如果您的应用程序支持拖放,并希望在用户按住鼠标键一定时间后开始拖放操作,则应使用此属性的值作为延迟时间。
访问功能:
int | startDragTime() const |
通知信号:
void | startDragTimeChanged(int startDragTime) |
另请参阅 startDragDistance 和拖放。
[read-only]
startDragVelocity : const int
该属性保留了鼠标在按住按钮的情况下开始拖放操作时的移动速度限制(以像素/秒为单位)。值为 0 表示没有此限制。
访问功能:
int | startDragVelocity() const |
另请参阅 startDragDistance 和拖放。
[read-only]
tabFocusBehavior : const Qt::TabFocusBehavior
此属性保存按下 tab 键时的焦点行为。
注意: 请勿在 QML 中绑定此值,因为更改通知信号尚未实现。
访问函数:
Qt::TabFocusBehavior | tabFocusBehavior() const |
通知信号:
void | tabFocusBehaviorChanged(Qt::TabFocusBehavior tabFocusBehavior) |
[read-only]
touchDoubleTapDistance : const int
该属性以像素为单位,表示手指在连续轻按两次后仍能被检测为轻按两次的最大移动距离。
访问功能:
int | touchDoubleTapDistance() const |
useHoverEffects : bool
此属性表示 UI 元素是否使用悬停效果。
如果用户界面元素应使用悬停效果,则该属性为true
。这是在桌面平台上使用鼠标指针的标准行为,而在触摸平台上则可以避免悬停事件传递的开销。
访问功能:
bool | useHoverEffects() const |
void | setUseHoverEffects(bool useHoverEffects) |
Notifier 信号:
void | useHoverEffectsChanged(bool useHoverEffects) |
[read-only]
useRtlExtensions : const bool
该属性表示写入方向。
如果启用了从右到左的写入方向,则该属性为true
,否则为false
。
访问功能:
bool | useRtlExtensions() const |
[read-only]
wheelScrollLines : const int
每次滚轮点击默认滚动的行数。
访问功能:
int | wheelScrollLines() const |
Notifier 信号:
void | wheelScrollLinesChanged(int scrollLines) |
成员函数 文档
[since 6.8]
void QStyleHints::setColorScheme(Qt::ColorScheme scheme)
将应用程序使用的配色方案设置为明确的scheme ,如果scheme 是Qt::ColorScheme::Unknown ,则还原为系统当前的配色方案。
注: 属性colorScheme 的设置函数。
该函数在 Qt 6.8 中引入。
另请参阅 colorScheme() 。
[since 6.8]
void QStyleHints::unsetColorScheme()
将配色方案恢复为系统当前配色方案。
注: 属性colorScheme 的重置函数。
此函数在 Qt 6.8 中引入。
© 2025 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.