Bearded Beaver
Bearded Beaver

Reputation: 656

QML window prevent focus stealing

I'm developing hybrid qml/qwidget application with qml-based popup notification system. Notifications are stored in list model and I'm using QML Instantiator to create and handle popups.

My problem is that every time new notification pops up it steals focus from the main widow. Note, that I'm using QMainWindow as a main window for the application.

Here is QML code snippet:

Instantiator {
id: instantiator
model: notificationCenter
delegate:
    Window {
    id: notificationWindow
    color: "transparent"
...

Variable notificationCenter is QAbstractListModel-derived object that contains all active notifications and some settings, including list of notifications:

QList <iNotification *> m_notifications;

It also contains QQmlEngine and QQmlComponent to load QML code with notification interface.

Popup is implemented using animation of QML window Y coordinate. Notification object is created with default y = QApplication::desktop()->availableGeometry().height() - 10 after adding new notification to the list recalculateGeometry function is called, which recalculates Y coordinates of all notifications and animates all notification windows:

Behavior on y {
    NumberAnimation {
        duration: 300
    }
}

So the popup itself is handled by Instantiator

Adding Qt.WA_ShowWithoutActivating to window flags has no effect.

UPD: I've managed to fix this. Window steals focus with the following flags:

flags: Qt.FramelessWindowHint | Qt.WA_ShowWithoutActivating |  Qt.WindowStaysOnTopHint

But (surprisingly) does not steal focus with the following flags:

flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Popup

Upvotes: 0

Views: 1969

Answers (1)

Bearded Beaver
Bearded Beaver

Reputation: 656

Solution found, use

flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Popup

instead of

flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WA_ShowWithoutActivating

Upvotes: 1

Related Questions