QDialog Windows taskbar icon
-
Hello!
I just can not understand one seemingly basic thing.
If we want to show our custom dialog, we can do smth like this:OurDialog * dlg = new OurDialog; // (this); dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->show(); dlg->raise(); dlg->activateWindow(); hide(); // hide MainWindow
Depending on giving a parent to constructor or not we can make taskbar icon visible or not.
But how to make the icon not only visible but also active?Moreover, if we move the string
hide(); // hide MainWindow
before
dlg->show();
The taskbar icon will be active, but in this case we'll get a "blinking effect" on showing the dialog.
So is there any possibility to hide MainWindow, show Dialog and make the taskbar icon active?Thank you!
-
Hi,
It's the call to activateWindow that triggers the "blinking effect".
What do you mean by "make icon active" ?
-
Thanks a lot for reply!
Blinking effect takes place because of the micro-delay between states when MainWindow is hidden and Dialog is shown. So we can avoid this situation by showing Qdialog at first and hiding MainWindow after that.
But, to my mind, it's strange behavior when we are in program (in dialog), but it's shown as inactive.
In this picture Chrome have active icon in taskbar. -
@CppHamster
Well the easiest "fix" that jumps into my mind would be,move
your mainwindow offscreen instead of hiding it.//hide(); move(-width(),-height());
-
@J-Hilk
Elegantly, but doesnt work:) I've tried it - we have two icons in taskbar:
-
@CppHamster
what about hiding the main-window and activate the dialog window afterwards. (swapdlg->activateWindow();
andhide(); // hide MainWindow
)
I think this should avoid the blinking effect in the taskbar.But note that you are working on a very MS Windows specific workaround. If you plan to support multiple platforms keep in mind that this might work differently or not even work at all.
-
@raven-worx Thank you for reply!
Unfortunately, it doesn't work.The "blinking effect" appears not in the taskbar, but on the screen whan we are looking at the changing the dialogs. To avoid this effect, i'm using this small hack:
MyDialog dlg; ... connect(dlg, SIGNAL(sl_dlgIsShown()), this, SLOT(hide()), Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection)); ...
where
void MyDialog::showEvent(QShowEvent *event) { QDialog::showEvent(event); QTimer::singleShot(0, this, SIGNAL(sl_dlgIsShown())); }
But in this case the taskbar application icon is set anactive. To my mind it's rather strange behaviour since we are still use active dialog of our program.
Anyway, even in small test widget project with simple code i've typed above, there is a strange question with taskbar icon appears too. It's inactive after hiding MainWindow. And it depends on the order of the hide() calling: the icon remains active only if we call hide() firstly.
It become inactive even if we do this:void MainWindow::st_showDlg() { Dialog * dlg = new Dialog; dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->show(); dlg->raise(); // we don't have to call this string, it can be simply commented dlg->activateWindow(); hide(); dlg->show(); dlg->raise(); // ... dlg->activateWindow(); }
And, i think it's strange behavoiur of the takbar icon of the application.
Maybe, i do smth wrong. And sure we can even use a widget and create it in our form and raise() then.
But using a QDialog written for this purpose gives us this strange behavior of the taskbar icon of our application. -
I faced similar issue.
Solved it using
QApplication::alert(Widget*, 1); // Prevent application icon to blink in taskbar (will blink 1ms, not visible)
This function was introduced in Qt 4.3.