Jump to content

Qt for HarmonyOS/qtohosextras doc/Keep Screen On Example

From Qt Wiki
Revision as of 05:36, 17 September 2026 by Shawn Luo (talk | contribs) (Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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: