Qt World Summit: Register Today!

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);
    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



    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!

  • Lifetime Qt Champion


    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.

  • Moderators

    Well the easiest "fix" that jumps into my mind would be, move your mainwindow offscreen instead of hiding it.


  • @J-Hilk
    Elegantly, but doesnt work:) I've tried it - we have two icons in taskbar:

  • Moderators

    what about hiding the main-window and activate the dialog window afterwards. (swap dlg->activateWindow(); and hide(); // 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));


    void MyDialog::showEvent(QShowEvent *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->raise(); // we don't have to call this string, it can be simply commented
        dlg->raise(); // ...

    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.

Log in to reply