Deliver WindowActivate/Deactivate events to QWindow
We need those events to trigger palette color group changes in QQuickItem without having to connect every item to yet another QWindow signal. Task-number: QTBUG-93752 Pick-to: 6.2 Change-Id: I8534808cdaab828e5876f8fda31567aeb1b4272a Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
421c69fde5
commit
b65159a5ea
@ -3478,8 +3478,16 @@ void QGuiApplicationPrivate::notifyLayoutDirectionChange()
|
||||
}
|
||||
}
|
||||
|
||||
void QGuiApplicationPrivate::notifyActiveWindowChange(QWindow *)
|
||||
void QGuiApplicationPrivate::notifyActiveWindowChange(QWindow *prev)
|
||||
{
|
||||
if (prev) {
|
||||
QEvent de(QEvent::WindowDeactivate);
|
||||
QCoreApplication::sendEvent(prev, &de);
|
||||
}
|
||||
if (self->focus_window) {
|
||||
QEvent ae(QEvent::WindowActivate);
|
||||
QCoreApplication::sendEvent(focus_window, &ae);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -1921,6 +1921,7 @@ void QApplicationPrivate::notifyActiveWindowChange(QWindow *previous)
|
||||
if (widget->inherits("QAxHostWidget"))
|
||||
widget->setFocus(Qt::ActiveWindowFocusReason);
|
||||
}
|
||||
// don't call base class to avoid double delivery of WindowActivate/Deactivate events
|
||||
}
|
||||
|
||||
/*!internal
|
||||
|
@ -109,6 +109,7 @@ private slots:
|
||||
void testBlockingWindowShownAfterModalDialog();
|
||||
void generatedMouseMove();
|
||||
void keepPendingUpdateRequests();
|
||||
void activateDeactivateEvent();
|
||||
|
||||
private:
|
||||
QPoint m_availableTopLeft;
|
||||
@ -2604,6 +2605,48 @@ void tst_QWindow::keepPendingUpdateRequests()
|
||||
QTRY_VERIFY(!platformWindow->hasPendingUpdateRequest());
|
||||
}
|
||||
|
||||
void tst_QWindow::activateDeactivateEvent()
|
||||
{
|
||||
class Window : public QWindow
|
||||
{
|
||||
public:
|
||||
using QWindow::QWindow;
|
||||
|
||||
int activateCount = 0;
|
||||
int deactivateCount = 0;
|
||||
protected:
|
||||
bool event(QEvent *e)
|
||||
{
|
||||
switch (e->type()) {
|
||||
case QEvent::WindowActivate:
|
||||
++activateCount;
|
||||
break;
|
||||
case QEvent::WindowDeactivate:
|
||||
++deactivateCount;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QWindow::event(e);
|
||||
}
|
||||
};
|
||||
|
||||
Window w1;
|
||||
Window w2;
|
||||
|
||||
w1.show();
|
||||
w1.requestActivate();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&w1));
|
||||
QCOMPARE(w1.activateCount, 1);
|
||||
QCOMPARE(w1.deactivateCount, 0);
|
||||
|
||||
w2.show();
|
||||
w2.requestActivate();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&w2));
|
||||
QCOMPARE(w1.deactivateCount, 1);
|
||||
QCOMPARE(w2.activateCount, 1);
|
||||
}
|
||||
|
||||
#include <tst_qwindow.moc>
|
||||
QTEST_MAIN(tst_QWindow)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user