'How to find out the screen number from qml code?
I need to find out whether the popup is visible on the screen. In Qt, I would call
qApp->desktop()->screenNumber(this)
within the widget class function.
This code returns -1 when there is no screen number because the given widget is not visible on any screen. I need to find out when this case scenario happens to show the widget on default position on primary screen (when the given screen is not available).
I have no idea how to find out the current screen number in QML code or other way that the pop up is not visible.
Solution 1:[1]
I solved the issue by creating a subclass from QQuickWindow, setting the appropriate flags
setFlags(Qt::WindowStaysOnTopHint | Qt::Popup );
and creating a function which can be called to find out whether the popup is visible based on the pixel coordinates of the popup
bool BlinkReminderWindow::existPointOnScreen(int x, int y)
{
return QGuiApplication::screenAt(QPoint(x,y))!=nullptr;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrej Fogelton |