Sv443
Sv443

Reputation: 749

How to show taskbar icon when using QSplashScreen

So I have the following code:

QString splashImageFilePath = ":/images/Splashscreens/startup.png";

QSplashScreen * splash = new QSplashScreen();
splash->setPixmap(QPixmap(splashImageFilePath));

splash->show();
splash->raise();

This runs fine and the splash screen shows up exactly like I want it to but it doesn't show an icon in the taskbar and so it is possible to click on another window and never be able to see the splash bar ever again (it hides behind other windows).

I've already tried to use the window flag Qt::WindowStaysOnTopHint but if I use this, there's still no icon in the taskbar and now it's always on top of all other windows (which I don't want).

I've looked through a few window flags so far and have googled for quite a while I'm trying to show it.

Also, I know I can give the constructor a parent, but this code is inside the main.cpp and so I don't have a way of giving it a parent window (a QWidget with an empty constructor also didn't work).

TLDR: I want my QSplashScreen to have an icon in the task bar.

Thank you in advance!

Upvotes: 2

Views: 452

Answers (2)

Loqenc
Loqenc

Reputation: 46

splash->setWindowFlag(Qt::Tool, false);
splash->show();

Upvotes: 0

Robert
Robert

Reputation: 807

A little late, but I ran into the same problem and fixed it using WinAPI directly:

QSplashScreen splash;
splash.setPixmap(QPixmap(splashImageFilePath));

// ensure that taskbar icon is shown while the splash screen is active
int exstyle = GetWindowLong(reinterpret_cast<HWND>(splash.winId()), GWL_EXSTYLE);
SetWindowLong(reinterpret_cast<HWND>(splash.winId()), GWL_EXSTYLE, exstyle & ~WS_EX_TOOLWINDOW);

splash.show();

Upvotes: 3

Related Questions