Question

I'm working on a project in Qt (PySide, but any Qt solution is welcome). I need to have an image fade in and do random animation. That is done, but it creates it's own taskbar item (yuck)! Code:

self.img_Check = QPixmap("resources/checkmark.png")
self.lab = QSplashScreen(self.img_Check)
self.lab.setWindowFlags(Qt.WindowStaysOnTopHint)
self.lab.setMask(self.img_Check.mask())

If I remove the setWindowFlags(Qt.WindowStaysOnTopHint) then it works perfectly, but it's not "Always on Top" and the user won't see the animation if he's using another application.

There's got to be a way to make an always-on-top animation without creating a menu bar item, but I'm not sure how. I do have a QMainWindow, in case you are curious.

I tried tons of flag combinations, and I can't do all 3: - Display on top of other Windows, like MS-Word. - Without taking over the active window status. - No taskbar item appear for this animation's window.

Context: Just in case you are curious why I need to do this, the program backs up a user's files in the background, and when one is finished processing, it fades in a "checkmark" icon at 50% opacity for a few seconds, so the user knows the backup is completed. I cannot use another way of indicating the backup is completed. That is the specification.

Était-ce utile?

La solution

When you call setWindowFlags, you remove all window flags except the flags you've specified in the argument. So Qt.SplashScreen flag is removed and the window is no longer a splash screen.

You should specify Qt.WindowStaysOnTopHint as the second argument of QSplashScreen constructor. See the docs:

QSplashScreen::QSplashScreen(const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0)

There should be no need to set the widget flags, f, except perhaps Qt::WindowStaysOnTopHint.

If you would need to add Qt.WindowStaysOnTopHint dynamically later, you can do something like

self.lab.setWindowFlags(self.lab.windowFlags() | Qt.WindowStaysOnTopHint)

or

self.lab.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top