0
votes

I am trying to make taskbar icon of my application visible after minimizing my window. My window can be displayed by show() or showFullScreen(), so my code for hiding window is:

w.setWindowFlags(w.windowFlags() | Qt::WindowStaysOnTopHint);

I also tried

w.setWindowFlags(w.windowFlags() | Qt::WindowStaysOnTopHint | Qt::Tool | etc);

but still the same: application is minimized but there is no icon on taskbar.

From here I learned that setWindowFlags:

Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again

But I can't use show() 'cause I wanna hide it.

How this can be done? Should I use WinApi or there is a QT-way, that I missed? (Qt::WindowStaysOnTopHint flag is necessary)

UPD1: I have my own system tray implemented, by I need icon on taskbar

UPD2: I've tried both showMinimized() and setWindowState(Qt::WindowMinimized). In first case there is icon on taskbar but after restoring the window (which was showed by showFullScreen()) there are window controls: minimize, close. caption etc. In second case it minimizes and restores correctly as I want, but there is no icon on taskbar.

1
From Managing Taskbar Buttons: "To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window." - I don't know why you are using Qt::Tool. Besides that, there is a difference between a hidden window and a minimized window. The former will not get a taskbar button.IInspectable
I just said that I tried different combinations of flagsuser2123079
Do you implement QSystemTrayIcon ?PnotNP
Minimise the app rather than hiding your main windowDavid Heffernan
Did you try QWindow::showMinimized() instead of setWindowFlags?Evgeny

1 Answers

0
votes

Well I did what I want. But I used WinApi for that. Hope this will help to somebody. So, after all

  • for minimizing I use following things:

    ShowWindow(hwnd, SW_SHOWMINIMIZED); 
    
  • for restoring to "prev" state I use:

       widget->show(); 
       // or
       widget->showFullScreen();
    
  • Setting stayOnTop flag is done by:

    // SWP_NOMOVE | SWP_NOSIZE are for ignoring 3rd, 4th, 5th, 6th parameters of the SetWindowPos function
    SetWindowPos(hwnd, stayOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);