简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM