Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDialog Windows taskbar icon
QtWS25 Last Chance

QDialog Windows taskbar icon

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CppHamster
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It's the call to activateWindow that triggers the "blinking effect".

      What do you mean by "make icon active" ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CppHamster
        wrote on last edited by
        #3

        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.

        0_1505460839441_qt-example.jpg
        In this picture Chrome have active icon in taskbar.

        J.HilkJ 1 Reply Last reply
        0
        • C CppHamster

          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.

          0_1505460839441_qt-example.jpg
          In this picture Chrome have active icon in taskbar.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

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

          //hide();
          move(-width(),-height());
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CppHamster
            wrote on last edited by CppHamster
            #5

            @J-Hilk
            Elegantly, but doesnt work:) I've tried it - we have two icons in taskbar:
            0_1505462760375_qt-example2.jpg

            raven-worxR 1 Reply Last reply
            0
            • C CppHamster

              @J-Hilk
              Elegantly, but doesnt work:) I've tried it - we have two icons in taskbar:
              0_1505462760375_qt-example2.jpg

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @CppHamster
              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.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              C 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @CppHamster
                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.

                C Offline
                C Offline
                CppHamster
                wrote on last edited by CppHamster
                #7

                @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.

                N 1 Reply Last reply
                0
                • C CppHamster

                  @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.

                  N Offline
                  N Offline
                  no_barth
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved