Qt for HarmonyOS/qtohosextras doc/Screen Display ID Example: Difference between revisions
Add code snippets to example pages (QTFOROH-2307) |
Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Screen Display ID Example = | = Screen Display ID Example = | ||
| Line 23: | Line 21: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/ | Files: | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Screen_Display_ID_Example_-_main.cpp|screendisplayid/main.cpp]] | |||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Screen_Display_ID_Example_-_screendisplayid.pro|screendisplayid/screendisplayid.pro]] | |||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Latest revision as of 06:36, 17 September 2026
Screen Display ID Example
Demonstrates obtaining the native display ID of the screen a window is shown on.
The window shows the current display ID and a refresh button. The value is queried with QtOhosExtras::tryGetScreenDisplayId() for the screen of the window, once after the window is shown and again on every button click, so the window can be moved to another display and re-queried. A null result is shown as <invalid>.
void updateDisplayId(QWidget *window, QLabel *label)
{
auto displayId = QtOhosExtras::tryGetScreenDisplayId(window->windowHandle()->screen());
label->setText(
QStringLiteral("Display ID: %1")
.arg(displayId
? QString::number(*displayId)
: QLatin1String("<invalid>")));
}
Files: