Qt for HarmonyOS/qtohosextras doc/Keep Screen On Example: Difference between revisions
Fix example page conversion (QTFOROH-2307) |
Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307) |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Keep Screen On Example = | = Keep Screen On Example = | ||
| Line 9: | Line 7: | ||
The main window contains a checkbox. Toggling it calls QtOhosExtras::setWindowKeepScreenOn() with the window and the checkbox state, so the screen stays awake while the box is checked and the request is released when it is unchecked. The setting is tied to the given window. | The main window contains a checkbox. Toggling it calls QtOhosExtras::setWindowKeepScreenOn() with the window and the checkbox state, so the screen stays awake while the box is checked and the request is released when it is unchecked. The setting is tied to the given window. | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/ | <syntaxhighlight lang="cpp"> | ||
QCheckBox keepScreenOnCheckBox("Keep on", &window); | |||
QObject::connect( | |||
&keepScreenOnCheckBox, &QCheckBox::stateChanged, &window, | |||
[window = &window](int state) { | |||
QtOhosExtras::setWindowKeepScreenOn(window, state == Qt::Checked); | |||
}); | |||
</syntaxhighlight> | |||
Files: | |||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Keep_Screen_On_Example_-_keepscreenon.pro|keepscreenon/keepscreenon.pro]] | |||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Keep_Screen_On_Example_-_main.cpp|keepscreenon/main.cpp]] | |||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Latest revision as of 05:36, 17 September 2026
Keep Screen On Example
Demonstrates keeping the screen on while a window is displayed.
The main window contains a checkbox. Toggling it calls QtOhosExtras::setWindowKeepScreenOn() with the window and the checkbox state, so the screen stays awake while the box is checked and the request is released when it is unchecked. The setting is tied to the given window.
QCheckBox keepScreenOnCheckBox("Keep on", &window);
QObject::connect(
&keepScreenOnCheckBox, &QCheckBox::stateChanged, &window,
[window = &window](int state) {
QtOhosExtras::setWindowKeepScreenOn(window, state == Qt::Checked);
});
Files: