[Interest] Confusing activation behavior of floating windows
John Weeks
john at wavemetrics.com
Wed Nov 26 20:17:53 CET 2014
I am seeing confusing QEvent::WindowActivate events associated with floating windows on Macintosh. I wonder if someone can give me an explanation. Please excuse the length...
The code here is a vastly simplified version of actual application code.
I use code like this to make three floating windows. Note that each code block makes a floating window, shows it and activates it. There is also code to name everything so you can tell what you're seeing, and qDebug() statements so that I can tell the order of what's happening. (hope it comes through readable):
void MainWindow::onGoButton()
{
Qt::WindowFlags qtflags = Qt::Tool | Qt::WindowStaysOnTopHint;
qtflags = qtflags | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint;
qDebug() << "About to create Window A";
QWidget * wa = new QWidget(0, qtflags);
wa->setObjectName("Window A");
wa->setWindowTitle("Window A");
qDebug() << "About to show Window A";
wa->show();
qDebug() << "About to activate Window A";
QApplication::setActiveWindow(wa);
qDebug() << "About to create Window B";
QWidget * wb = new QWidget(0, qtflags);
wb->setObjectName("Window B");
wb->setWindowTitle("Window B");
qDebug() << "About to show Window B";
wb->show();
qDebug() << "About to activate Window B";
QApplication::setActiveWindow(wb);
qDebug() << "About to create Window C";
QWidget * wc = new QWidget(0, qtflags);
wc->setObjectName("Window C");
wc->setWindowTitle("Window C");
qDebug() << "About to show Window C";
wc->show();
qDebug() << "About to activate Window C";
QApplication::setActiveWindow(wc);
}
I also use QApplication::notify() to monitor QEvent::WindowActivate:
bool myApp::notify(QObject *object, QEvent *event)
{
if (event->type() == QEvent::WindowActivate)
{
qDebug() << "Window activate:" << object->objectName() << "and the active window is" << QApplication::activeWindow()->objectName();
}
return QApplication::notify(object, event);
}
On Macintosh using Qt 5.4 RC (which means Cocoa) on OS X 10.9.5 I get this output:
About to create Window A
About to show Window A
About to activate Window A
Window activate: "Window A" and the active window is "Window A"
About to create Window B
About to show Window B
About to activate Window B
Window activate: "Window B" and the active window is "Window B"
Window activate: "Window A" and the active window is "Window B"
About to create Window C
About to show Window C
About to activate Window C
Window activate: "Window B" and the active window is "Window C"
Window activate: "Window A" and the active window is "Window C"
Window activate: "Window C" and the active window is "Window C"
Note that the target for the event isn't always the same as what Qt thinks is the active window.
On Windows I get more reasonable output:
About to create Window A
About to show Window A
About to activate Window A
Window activate: "Window A" and the active window is "Window A"
About to create Window B
About to show Window B
About to activate Window B
Window activate: "Window B" and the active window is "Window B"
About to create Window C
About to show Window C
About to activate Window C
Window activate: "Window C" and the active window is "Window C"
Am I just seeing Cocoa weirdness? It looks like some of the time Qt is lying to me about the activating window. But if it's a Qt bug, then it's been there a long time- I also see it when building with Qt 4.8.6.
Thanks for any insight that can be offered!
-John Weeks
More information about the Interest
mailing list