1
votes

I have a Qt application which remains on top of other windows. The mainwindow is frameless and transparent. To put it above other windows I have followed the following procedure.

SetForegroundWindow((HWND)winId());
Qt::WindowFlags flags = this->windowFlags();
flags = flags & ~Qt::WindowMinimizeButtonHint;
this->setWindowFlags(flags|Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint );
ui.setupUi(this);

This code snippet brings my Qt mainwindow on top of all windows and also above taskbar. The problem is that whenever any region of taskbar is clicked the region of mainwindow over the taskabr goes behind the taskbar. The taskbar comes to the front. The mainwindow still remains above all other window.It appears that the bottom region of my mainwindow has gone behind the taskbar.

How can I prevent the taskbar from pushing the region of mainwindow behind itself ? I want to keep my window above all windows and also above the taskbar.

3
Are you sure you've asked yourself whether this design provides good user experience? As a user, I'd be mighty upset if something tried to obscure the taskbar at all times...Kuba hasn't forgotten Monica

3 Answers

2
votes

You can't. Qt::WindowsStaysOnTopHint marks a window with the WS_EX_TOPMOST window style, and all such windows can lie on top of each other. See Raymond Chen's occasional rants on The Old New Thing.

Your best bet is to limit the position of your window so that it can't be moved on top of the task bar.

1
votes

if you can access the windows api or Qt has an equivalent function you can use SetWindowPos

eg

SetWindowPos(hWnd, ((HWND)-1), 0, 0, width, height, 0); 

where hWnd is a handle to your window and width and height are the width and height of the screen (if you want it full screen). Passing -1 as an HWND will put the window above all other non-topmost windows. It will remain on top even after the window is deactivated.

0
votes

Thanks for the answers. Thanks Martin Bonner for providing the reference to the blog The Old New Thing.

I have tried an alternative by using a timer and raising my window over other taskbar. My window is completely transparent, frameless with no title bar and statusbar. It contains only a rectangular border and some buttons at the bottom.

I am raising the window every 500ms above the taskbar. So if the user clicks on any region in the taskbar , the portion of my window behind taskbar comes to the front again.

if (this->isActiveWindow() == false)
    this->raise();

Yes this way of raising window may induce race around conditions if any other application is using similar approach to raise itself above taskbar. So I guess to make sure this method works correctly two applications having similar approach to raise itself should not be run together.