Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qstylehints.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6#include <qstylehints.h>
8#include <qpa/qplatformintegration.h>
9#include <qpa/qplatformtheme.h>
10#include <private/qguiapplication_p.h>
11#include <qdebug.h>
12
14
15static inline QVariant hint(QPlatformIntegration::StyleHint h)
16{
17 return QGuiApplicationPrivate::platformIntegration()->styleHint(h);
18}
19
20static inline QVariant themeableHint(QPlatformTheme::ThemeHint th,
21 QPlatformIntegration::StyleHint ih)
22{
23 if (!QCoreApplication::instance()) {
24 qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
25 return QVariant();
26 }
27 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
28 const QVariant themeHint = theme->themeHint(th);
29 if (themeHint.isValid())
30 return themeHint;
31 }
32 return QGuiApplicationPrivate::platformIntegration()->styleHint(ih);
33}
34
35static inline QVariant themeableHint(QPlatformTheme::ThemeHint th)
36{
37 if (!QCoreApplication::instance()) {
38 qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
39 return QVariant();
40 }
41 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
42 const QVariant themeHint = theme->themeHint(th);
43 if (themeHint.isValid())
44 return themeHint;
45 }
46 return QPlatformTheme::defaultThemeHint(th);
47}
48
49/*!
50 \class QStyleHints
51 \since 5.0
52 \brief The QStyleHints class contains platform specific hints and settings.
53 \inmodule QtGui
54
55 An object of this class, obtained from QGuiApplication, provides access to certain global
56 user interface parameters of the current platform.
57
58 The platform provides most of these settings, and they are typically read-only.
59 End users can usually adjust them through platform-specific configuration mechanisms.
60 However, you can also adjust some settings programmatically through dedicated setter
61 functions, (for example, setColorScheme() or setShowShortcutsInContextMenus()),
62 which can be useful for testing or specialized application behavior. Any such adjustments
63 apply only to the current application.
64
65 Authors of custom user interface components should read
66 relevant settings to allow the components to exhibit the same behavior and feel as other
67 components.
68
69 \sa QGuiApplication::styleHints()
70 */
71QStyleHints::QStyleHints()
72 : QObject(*new QStyleHintsPrivate(), nullptr)
73{
74}
75
76/*!
77 Sets the \a mouseDoubleClickInterval.
78 \internal
79 \sa mouseDoubleClickInterval()
80 \since 5.3
81*/
82void QStyleHints::setMouseDoubleClickInterval(int mouseDoubleClickInterval)
83{
84 Q_D(QStyleHints);
85 if (d->m_mouseDoubleClickInterval == mouseDoubleClickInterval)
86 return;
87 d->m_mouseDoubleClickInterval = mouseDoubleClickInterval;
88 emit mouseDoubleClickIntervalChanged(mouseDoubleClickInterval);
89}
90
91/*!
92 \property QStyleHints::mouseDoubleClickInterval
93 \brief the time limit in milliseconds that distinguishes a double click
94 from two consecutive mouse clicks.
95*/
96int QStyleHints::mouseDoubleClickInterval() const
97{
98 Q_D(const QStyleHints);
99 return d->m_mouseDoubleClickInterval >= 0 ?
100 d->m_mouseDoubleClickInterval :
101 themeableHint(QPlatformTheme::MouseDoubleClickInterval, QPlatformIntegration::MouseDoubleClickInterval).toInt();
102}
103
104/*!
105 \property QStyleHints::mouseDoubleClickDistance
106 \brief the maximum distance, in pixels, that the mouse can be moved between
107 two consecutive mouse clicks and still have it detected as a double-click
108 \since 5.14
109*/
110int QStyleHints::mouseDoubleClickDistance() const
111{
112 Q_D(const QStyleHints);
113 return d->m_mouseDoubleClickDistance >= 0 ?
114 d->m_mouseDoubleClickDistance :
115 themeableHint(QPlatformTheme::MouseDoubleClickDistance, QPlatformIntegration::MouseDoubleClickDistance).toInt();
116}
117
118/*!
119 \property QStyleHints::touchDoubleTapDistance
120 \brief the maximum distance, in pixels, that a finger can be moved between
121 two consecutive taps and still have it detected as a double-tap
122 \since 5.14
123*/
124int QStyleHints::touchDoubleTapDistance() const
125{
126 Q_D(const QStyleHints);
127 return d->m_touchDoubleTapDistance >= 0 ?
128 d->m_touchDoubleTapDistance :
129 themeableHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
130}
131
132/*!
133 \property QStyleHints::colorScheme
134 \brief the color scheme used by the application.
135
136 By default, this follows the system's default color scheme (also known as appearance),
137 and changes when the system color scheme changes (e.g. during dusk or dawn).
138 Setting the color scheme to an explicit value will override the system setting and
139 ignore any changes to the system's color scheme. However, doing so is a hint to the
140 system, and overriding the color scheme is not supported on all platforms.
141
142 Resetting this property, or setting it to \l{Qt::ColorScheme::Unknown}, will remove
143 the override and make the application follow the system default again. The property
144 value will change to the color scheme the system currently has.
145
146 When this property changes, Qt will read the system palette and update the default
147 palette, but won't overwrite palette entries that have been explicitly set by the
148 application. When the colorSchemeChange() signal gets emitted, the old palette is
149 still in effect.
150
151 Application-specific colors should be selected to work well with the effective
152 palette, taking the current color scheme into account. To update application-
153 specific colors when the effective palette changes, handle
154 \l{QEvent::}{PaletteChange} or \l{QEvent::}{ApplicationPaletteChange} events.
155
156 \sa Qt::ColorScheme, QGuiApplication::palette(), QEvent::PaletteChange
157 \since 6.5
158*/
159Qt::ColorScheme QStyleHints::colorScheme() const
160{
161 Q_D(const QStyleHints);
162 return d->colorScheme();
163}
164
165/*!
166 \since 6.8
167
168 Sets the color scheme used by the application to an explicit \a scheme, or
169 revert to the system's current color scheme if \a scheme is Qt::ColorScheme::Unknown.
170*/
171void QStyleHints::setColorScheme(Qt::ColorScheme scheme)
172{
173 if (!QCoreApplication::instance()) {
174 qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
175 return;
176 }
177 if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
178 theme->requestColorScheme(scheme);
179}
180
181/*!
182 \fn void QStyleHints::unsetColorScheme()
183 \since 6.8
184
185 Restores the color scheme to the system's current color scheme.
186*/
187
188
189/*!
190 \property QStyleHints::accessibility
191 \brief The application's accessibility hints.
192
193 The accessibility hints encapsulates platform dependent accessibility settings
194 such as whether the user wishes the application to be in high contrast or not.
195
196 \sa QAccessibilityHints
197 \since 6.10
198*/
199const QAccessibilityHints *QStyleHints::accessibility() const
200{
201 Q_D(const QStyleHints);
202 return d->accessibilityHints();
203}
204
205/*!
206 \property QStyleHints::toolTipWakeUpDelay
207 \brief The delay before tool tips should be shown.
208 \since 6.12
209 \sa QWidget::toolTip, {QtQuick.Controls::ToolTip::delay}
210*/
211std::chrono::milliseconds QStyleHints::toolTipWakeUpDelay() const
212{
213 Q_D(const QStyleHints);
214 return d->m_toolTipWakeUpDelay;
215}
216
217void QStyleHints::setToolTipWakeUpDelay(std::chrono::milliseconds toolTipWakeUpDelay)
218{
219 Q_D(QStyleHints);
220 if (d->m_toolTipWakeUpDelay == toolTipWakeUpDelay)
221 return;
222 d->m_toolTipWakeUpDelay = toolTipWakeUpDelay;
223 emit toolTipWakeUpDelayChanged(toolTipWakeUpDelay);
224 emit toolTipWakeUpDelayAsMSecChanged(toolTipWakeUpDelayAsMSec());
225}
226
227/*!
228 \property QStyleHints::toolTipWakeUpDelayAsMSec
229 \brief The delay, in milliseconds, before tool tips should be shown.
230 \since 6.12
231 \sa toolTipWakeUpDelay, {QtQuick.Controls::ToolTip::delay}
232*/
233int QStyleHints::toolTipWakeUpDelayAsMSec() const
234{
235 Q_D(const QStyleHints);
236 return q26::saturating_cast<int>(d->m_toolTipWakeUpDelay.count());
237}
238
239Qt::MouseButtons QStyleHints::menuActivationButtons() const
240{
241 return themeableHint(QPlatformTheme::MenuActivationButtons).value<Qt::MouseButtons>();
242}
243
244/*!
245 Sets the \a mousePressAndHoldInterval.
246 \internal
247 \sa mousePressAndHoldInterval()
248 \since 5.7
249*/
250void QStyleHints::setMousePressAndHoldInterval(int mousePressAndHoldInterval)
251{
252 Q_D(QStyleHints);
253 if (d->m_mousePressAndHoldInterval == mousePressAndHoldInterval)
254 return;
255 d->m_mousePressAndHoldInterval = mousePressAndHoldInterval;
256 emit mousePressAndHoldIntervalChanged(mousePressAndHoldInterval);
257}
258
259/*!
260 \property QStyleHints::mousePressAndHoldInterval
261 \brief the time limit in milliseconds that activates
262 a press and hold.
263
264 \since 5.3
265*/
266int QStyleHints::mousePressAndHoldInterval() const
267{
268 Q_D(const QStyleHints);
269 return d->m_mousePressAndHoldInterval >= 0 ?
270 d->m_mousePressAndHoldInterval :
271 themeableHint(QPlatformTheme::MousePressAndHoldInterval, QPlatformIntegration::MousePressAndHoldInterval).toInt();
272}
273
274/*!
275 Sets the \a startDragDistance.
276 \internal
277 \sa startDragDistance()
278 \since 5.3
279*/
280void QStyleHints::setStartDragDistance(int startDragDistance)
281{
282 Q_D(QStyleHints);
283 if (d->m_startDragDistance == startDragDistance)
284 return;
285 d->m_startDragDistance = startDragDistance;
286 emit startDragDistanceChanged(startDragDistance);
287}
288
289/*!
290 \property QStyleHints::startDragDistance
291 \brief the distance, in pixels, that the mouse must be moved with a button
292 held down before a drag and drop operation will begin.
293
294 If you support drag and drop in your application, and want to start a drag
295 and drop operation after the user has moved the cursor a certain distance
296 with a button held down, you should use this property's value as the
297 minimum distance required.
298
299 For example, if the mouse position of the click is stored in \c startPos
300 and the current position (e.g. in the mouse move event) is \c currentPos,
301 you can find out if a drag should be started with code like this:
302
303 \snippet code/src_gui_kernel_qapplication.cpp 6
304
305 \sa startDragTime, QPoint::manhattanLength(), {Drag and Drop}
306*/
307int QStyleHints::startDragDistance() const
308{
309 Q_D(const QStyleHints);
310 return d->m_startDragDistance >= 0 ?
311 d->m_startDragDistance :
312 themeableHint(QPlatformTheme::StartDragDistance, QPlatformIntegration::StartDragDistance).toInt();
313}
314
315/*!
316 Sets the \a startDragDragTime.
317 \internal
318 \sa startDragTime()
319 \since 5.3
320*/
321void QStyleHints::setStartDragTime(int startDragTime)
322{
323 Q_D(QStyleHints);
324 if (d->m_startDragTime == startDragTime)
325 return;
326 d->m_startDragTime = startDragTime;
327 emit startDragTimeChanged(startDragTime);
328}
329
330/*!
331 \property QStyleHints::startDragTime
332 \brief the time, in milliseconds, that a mouse button must be held down
333 before a drag and drop operation will begin.
334
335 If you support drag and drop in your application, and want to start a drag
336 and drop operation after the user has held down a mouse button for a
337 certain amount of time, you should use this property's value as the delay.
338
339 \sa startDragDistance, {Drag and Drop}
340*/
341int QStyleHints::startDragTime() const
342{
343 Q_D(const QStyleHints);
344 return d->m_startDragTime >= 0 ?
345 d->m_startDragTime :
346 themeableHint(QPlatformTheme::StartDragTime, QPlatformIntegration::StartDragTime).toInt();
347}
348
349/*!
350 \property QStyleHints::startDragVelocity
351 \brief the limit for the velocity, in pixels per second, that the mouse may
352 be moved, with a button held down, for a drag and drop operation to begin.
353 A value of 0 means there is no such limit.
354
355 \sa startDragDistance, {Drag and Drop}
356*/
357int QStyleHints::startDragVelocity() const
358{
359 return themeableHint(QPlatformTheme::StartDragVelocity, QPlatformIntegration::StartDragVelocity).toInt();
360}
361
362/*!
363 Sets the \a keyboardInputInterval.
364 \internal
365 \sa keyboardInputInterval()
366 \since 5.3
367*/
368void QStyleHints::setKeyboardInputInterval(int keyboardInputInterval)
369{
370 Q_D(QStyleHints);
371 if (d->m_keyboardInputInterval == keyboardInputInterval)
372 return;
373 d->m_keyboardInputInterval = keyboardInputInterval;
374 emit keyboardInputIntervalChanged(keyboardInputInterval);
375}
376
377/*!
378 \property QStyleHints::keyboardInputInterval
379 \brief the time limit, in milliseconds, that distinguishes a key press
380 from two consecutive key presses.
381*/
382int QStyleHints::keyboardInputInterval() const
383{
384 Q_D(const QStyleHints);
385 return d->m_keyboardInputInterval >= 0 ?
386 d->m_keyboardInputInterval :
387 themeableHint(QPlatformTheme::KeyboardInputInterval, QPlatformIntegration::KeyboardInputInterval).toInt();
388}
389
390#if QT_DEPRECATED_SINCE(6, 5)
391/*!
392 \property QStyleHints::keyboardAutoRepeatRate
393 \brief the rate, in events per second, in which additional repeated key
394 presses will automatically be generated if a key is being held down.
395 \deprecated [6.5] Use keyboardAutoRepeatRateF() instead.
396*/
397int QStyleHints::keyboardAutoRepeatRate() const
398{
399 return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt();
400}
401#endif
402
403/*!
404 \property QStyleHints::keyboardAutoRepeatRateF
405 \since 6.5
406 \brief the rate, in events per second, in which additional repeated key
407 presses will automatically be generated if a key is being held down.
408*/
409qreal QStyleHints::keyboardAutoRepeatRateF() const
410{
411 return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toReal();
412}
413
414/*!
415 Sets the \a cursorFlashTime.
416 \internal
417 \sa cursorFlashTime()
418 \since 5.3
419*/
420void QStyleHints::setCursorFlashTime(int cursorFlashTime)
421{
422 Q_D(QStyleHints);
423 if (d->m_cursorFlashTime == cursorFlashTime)
424 return;
425 d->m_cursorFlashTime = cursorFlashTime;
426 emit cursorFlashTimeChanged(cursorFlashTime);
427}
428
429/*!
430 \property QStyleHints::cursorFlashTime
431 \brief the text cursor's flash (blink) time in milliseconds.
432
433 The flash time is the time used to display, invert and restore the
434 caret display. Usually the text cursor is displayed for half the cursor
435 flash time, then hidden for the same amount of time.
436*/
437int QStyleHints::cursorFlashTime() const
438{
439 Q_D(const QStyleHints);
440 return d->m_cursorFlashTime >= 0 ?
441 d->m_cursorFlashTime :
442 themeableHint(QPlatformTheme::CursorFlashTime, QPlatformIntegration::CursorFlashTime).toInt();
443}
444
445/*!
446 \property QStyleHints::showIsFullScreen
447 \brief whether the platform defaults to fullscreen windows.
448
449 This property is \c true if the platform defaults to windows being fullscreen,
450 otherwise \c false.
451
452 \note The platform may still choose to show certain windows non-fullscreen,
453 such as popups or dialogs. This property only reports the default behavior.
454
455 \sa QWindow::show(), showIsMaximized()
456*/
457bool QStyleHints::showIsFullScreen() const
458{
459 return hint(QPlatformIntegration::ShowIsFullScreen).toBool();
460}
461
462/*!
463 \property QStyleHints::showIsMaximized
464 \brief whether the platform defaults to maximized windows.
465
466 This property is \c true if the platform defaults to windows being maximized,
467 otherwise \c false.
468
469 \note The platform may still choose to show certain windows non-maximized,
470 such as popups or dialogs. This property only reports the default behavior.
471
472 \sa QWindow::show(), showIsFullScreen()
473 \since 5.6
474*/
475bool QStyleHints::showIsMaximized() const
476{
477 return hint(QPlatformIntegration::ShowIsMaximized).toBool();
478}
479
480/*!
481 \property QStyleHints::showShortcutsInContextMenus
482 \since 5.10
483 \brief \c true if the platform normally shows shortcut key sequences in
484 context menus, otherwise \c false.
485
486 Since Qt 5.13, the setShowShortcutsInContextMenus() function can be used to
487 override the platform default.
488
489 \sa Qt::AA_DontShowShortcutsInContextMenus
490*/
491bool QStyleHints::showShortcutsInContextMenus() const
492{
493 Q_D(const QStyleHints);
494 return d->m_showShortcutsInContextMenus >= 0
495 ? d->m_showShortcutsInContextMenus != 0
496 : themeableHint(QPlatformTheme::ShowShortcutsInContextMenus, QPlatformIntegration::ShowShortcutsInContextMenus).toBool();
497}
498
499void QStyleHints::setShowShortcutsInContextMenus(bool s)
500{
501 Q_D(QStyleHints);
502 if (s != showShortcutsInContextMenus()) {
503 d->m_showShortcutsInContextMenus = s ? 1 : 0;
504 emit showShortcutsInContextMenusChanged(s);
505 }
506}
507
508/*!
509 \property QStyleHints::contextMenuTrigger
510 \since 6.8
511 \brief mouse event used to trigger a context menu event.
512
513 The default on UNIX systems is to show context menu on mouse button press event, while on
514 Windows it is the mouse button release event. This property can be used to override the default
515 platform behavior.
516
517 \note Developers must use this property with great care, as it changes the default interaction
518 mode that their users will expect on the platform that they are running on.
519
520 \sa Qt::ContextMenuTrigger
521*/
522Qt::ContextMenuTrigger QStyleHints::contextMenuTrigger() const
523{
524 Q_D(const QStyleHints);
525 if (d->m_contextMenuTrigger == -1) {
526 return themeableHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool()
527 ? Qt::ContextMenuTrigger::Release
528 : Qt::ContextMenuTrigger::Press;
529 }
530 return Qt::ContextMenuTrigger(d->m_contextMenuTrigger);
531}
532
533void QStyleHints::setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger)
534{
535 Q_D(QStyleHints);
536 const Qt::ContextMenuTrigger currentTrigger = this->contextMenuTrigger();
537 d->m_contextMenuTrigger = int(contextMenuTrigger);
538 if (currentTrigger != contextMenuTrigger)
539 emit contextMenuTriggerChanged(contextMenuTrigger);
540}
541
542/*!
543 \property QStyleHints::menuSelectionWraps
544 \since 6.10
545 \brief menu selection wraps around.
546
547 Returns \c true if menu selection wraps. That is, whether key navigation moves
548 the selection to the first menu item again after the last menu item has been
549 reached, and vice versa.
550*/
551bool QStyleHints::menuSelectionWraps() const
552{
553 return themeableHint(QPlatformTheme::MenuSelectionWraps).toBool();
554}
555
556/*!
557 \property QStyleHints::passwordMaskDelay
558 \brief the time, in milliseconds, a typed letter is displayed unshrouded
559 in a text input field in password mode.
560*/
561int QStyleHints::passwordMaskDelay() const
562{
563 return themeableHint(QPlatformTheme::PasswordMaskDelay, QPlatformIntegration::PasswordMaskDelay).toInt();
564}
565
566/*!
567 \property QStyleHints::passwordMaskCharacter
568 \brief the character used to mask the characters typed into text input
569 fields in password mode.
570*/
571QChar QStyleHints::passwordMaskCharacter() const
572{
573 return themeableHint(QPlatformTheme::PasswordMaskCharacter, QPlatformIntegration::PasswordMaskCharacter).toChar();
574}
575
576/*!
577 \property QStyleHints::fontSmoothingGamma
578 \brief the gamma value used in font smoothing.
579*/
580qreal QStyleHints::fontSmoothingGamma() const
581{
582 return hint(QPlatformIntegration::FontSmoothingGamma).toReal();
583}
584
585/*!
586 \property QStyleHints::useRtlExtensions
587 \brief the writing direction.
588
589 This property is \c true if right-to-left writing direction is enabled,
590 otherwise \c false.
591*/
592bool QStyleHints::useRtlExtensions() const
593{
594 return hint(QPlatformIntegration::UseRtlExtensions).toBool();
595}
596
597/*!
598 \property QStyleHints::setFocusOnTouchRelease
599 \brief the event that should set input focus on focus objects.
600
601 This property is \c true if focus objects (line edits etc) should receive
602 input focus after a touch/mouse release. This is normal behavior on
603 touch platforms. On desktop platforms, the standard is to set
604 focus already on touch/mouse press.
605*/
606bool QStyleHints::setFocusOnTouchRelease() const
607{
608 return themeableHint(QPlatformTheme::SetFocusOnTouchRelease, QPlatformIntegration::SetFocusOnTouchRelease).toBool();
609}
610
611/*!
612 \property QStyleHints::tabFocusBehavior
613 \since 5.5
614 \brief The focus behavior on press of the tab key.
615
616 \note Do not bind this value in QML because the change notifier
617 signal is not implemented yet.
618*/
619
620Qt::TabFocusBehavior QStyleHints::tabFocusBehavior() const
621{
622 Q_D(const QStyleHints);
623 return Qt::TabFocusBehavior(d->m_tabFocusBehavior >= 0 ?
624 d->m_tabFocusBehavior :
625 themeableHint(QPlatformTheme::TabFocusBehavior, QPlatformIntegration::TabFocusBehavior).toInt());
626}
627
628/*!
629 Sets the \a tabFocusBehavior.
630 \internal
631 \sa tabFocusBehavior()
632 \since 5.7
633*/
634void QStyleHints::setTabFocusBehavior(Qt::TabFocusBehavior tabFocusBehavior)
635{
636 Q_D(QStyleHints);
637 if (d->m_tabFocusBehavior == tabFocusBehavior)
638 return;
639 d->m_tabFocusBehavior = tabFocusBehavior;
640 emit tabFocusBehaviorChanged(tabFocusBehavior);
641}
642
643/*!
644 \property QStyleHints::singleClickActivation
645 \brief whether items are activated by single or double click.
646
647 This property is \c true if items should be activated by single click, \c false
648 if they should be activated by double click instead.
649
650 \since 5.5
651*/
652bool QStyleHints::singleClickActivation() const
653{
654 return themeableHint(QPlatformTheme::ItemViewActivateItemOnSingleClick, QPlatformIntegration::ItemViewActivateItemOnSingleClick).toBool();
655}
656
657/*!
658 \property QStyleHints::useHoverEffects
659 \brief whether UI elements use hover effects.
660
661 This property is \c true if UI elements should use hover effects. This is the
662 standard behavior on desktop platforms with a mouse pointer, whereas
663 on touch platforms the overhead of hover event delivery can be avoided.
664
665 \since 5.8
666*/
667bool QStyleHints::useHoverEffects() const
668{
669 Q_D(const QStyleHints);
670 return (d->m_uiEffects >= 0 ?
671 d->m_uiEffects :
672 themeableHint(QPlatformTheme::UiEffects, QPlatformIntegration::UiEffects).toInt()) & QPlatformTheme::HoverEffect;
673}
674
675void QStyleHints::setUseHoverEffects(bool useHoverEffects)
676{
677 Q_D(QStyleHints);
678 if (d->m_uiEffects >= 0 && useHoverEffects == bool(d->m_uiEffects & QPlatformTheme::HoverEffect))
679 return;
680 if (d->m_uiEffects == -1)
681 d->m_uiEffects = 0;
682 if (useHoverEffects)
683 d->m_uiEffects |= QPlatformTheme::HoverEffect;
684 else
685 d->m_uiEffects &= ~QPlatformTheme::HoverEffect;
686 emit useHoverEffectsChanged(useHoverEffects);
687}
688
689/*!
690 \property QStyleHints::wheelScrollLines
691 \brief Number of lines to scroll by default for each wheel click.
692
693 \since 5.9
694*/
695int QStyleHints::wheelScrollLines() const
696{
697 Q_D(const QStyleHints);
698 if (d->m_wheelScrollLines > 0)
699 return d->m_wheelScrollLines;
700 return themeableHint(QPlatformTheme::WheelScrollLines, QPlatformIntegration::WheelScrollLines).toInt();
701}
702
703/*!
704 Sets the \a wheelScrollLines.
705 \internal
706 \sa wheelScrollLines()
707 \since 5.9
708*/
709void QStyleHints::setWheelScrollLines(int scrollLines)
710{
711 Q_D(QStyleHints);
712 if (d->m_wheelScrollLines == scrollLines)
713 return;
714 d->m_wheelScrollLines = scrollLines;
715 emit wheelScrollLinesChanged(scrollLines);
716}
717
718/*!
719 Sets the mouse quick selection threshold.
720 \internal
721 \sa mouseQuickSelectionThreshold()
722 \since 5.11
723*/
724void QStyleHints::setMouseQuickSelectionThreshold(int threshold)
725{
726 Q_D(QStyleHints);
727 if (d->m_mouseQuickSelectionThreshold == threshold)
728 return;
729 d->m_mouseQuickSelectionThreshold = threshold;
730 emit mouseQuickSelectionThresholdChanged(threshold);
731}
732
733/*!
734 \property QStyleHints::mouseQuickSelectionThreshold
735 \brief Quick selection mouse threshold in QLineEdit.
736
737 This property defines how much the mouse cursor should be moved along the y axis
738 to trigger a quick selection during a normal QLineEdit text selection.
739
740 If the property value is less than or equal to 0, the quick selection feature is disabled.
741
742 \since 5.11
743*/
744int QStyleHints::mouseQuickSelectionThreshold() const
745{
746 Q_D(const QStyleHints);
747 if (d->m_mouseQuickSelectionThreshold >= 0)
748 return d->m_mouseQuickSelectionThreshold;
749 return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt();
750}
751
752/*!
753 \internal
754 QStyleHintsPrivate::updateColorScheme - set a new color scheme.
755
756 This function is called by the QPA plugin when the system theme changes. This in
757 turn might be the result of an explicit request of a color scheme via setColorScheme.
758
759 Set \a colorScheme as the new color scheme of the QStyleHints.
760 The colorSchemeChanged signal will be emitted if present and new color scheme differ.
761 */
762void QStyleHintsPrivate::updateColorScheme(Qt::ColorScheme colorScheme)
763{
764 if (m_colorScheme == colorScheme)
765 return;
766 m_colorScheme = colorScheme;
767 Q_Q(QStyleHints);
768 emit q->colorSchemeChanged(colorScheme);
769}
770
771/*!
772 \internal
773
774 Helper function that updates the style hints when the theme changes
775*/
776void QStyleHintsPrivate::update(const QPlatformTheme *theme)
777{
778 Q_ASSERT(theme);
779 updateColorScheme(theme->colorScheme());
780 auto *accessibilityHintsPrivate = QAccessibilityHintsPrivate::get(accessibilityHints());
781 accessibilityHintsPrivate->updateContrastPreference(theme->contrastPreference());
782 accessibilityHintsPrivate->updateMotionPreference(theme->motionPreference());
783}
784
785QAccessibilityHints *QStyleHintsPrivate::accessibilityHints() const
786{
787 Q_Q(const QStyleHints);
788 if (!m_accessibilityHints)
789 const_cast<QStyleHintsPrivate *>(this)->m_accessibilityHints = new QAccessibilityHints(const_cast<QStyleHints*>(q));
790 return m_accessibilityHints;
791}
792
794{
795 Q_ASSERT(q);
796 return q->d_func();
797}
798
799QT_END_NAMESPACE
800
801#include "moc_qstylehints.cpp"
QAccessibilityHints * accessibilityHints() const
void update(const QPlatformTheme *theme)
Combined button and popup list for selecting options.
static QVariant themeableHint(QPlatformTheme::ThemeHint th, QPlatformIntegration::StyleHint ih)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
static QVariant themeableHint(QPlatformTheme::ThemeHint th)