3

I want to display an animated loader image on my table view while loading. The screenshot below shows an impression.

I have used an animated gif for that, displayed by setStyleSheet as centered background image.

Loader image

I face two issues:

  1. The gif is displayed, but not animated. Is it possible to display an animated gif as background image (via stylesheet)? Remark: In general an animated gif is possible as shown in Qt - How to show gif(animated) image in QGraphicsPixmapItem but there seems to be no animated gif with style sheets Animated Gif static in QStyleSheet
  2. I have problems to clear the image once loading is done. If I clear the stylesheet with setStyleSheet("") then it is still displayed. The only trick working for me is to override it as 1 pixel transparent image

Is there a solution to those issues or even a better approach (overlay widget? / specialized Qt widget for that)?

(My code exampled with Qt 5.4 / Win7)


Edit: https://stackoverflow.com/a/26958738/356726 shows how such a gif can be animated, but I have no idea to use that in such a kind of overlay / background style.

Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228

2 Answers2

1

Use QProgressIndicator insted of gif animation.

PS: it says that it Qt4, but it works with Qt5.

RazrFalcon
  • 787
  • 7
  • 17
  • Interesting hint, but it seems to be a normal widget. Does it work as overlay, as I want to display the indicator as part of the table view. Or is there an easy way to center a widget over an existing one (I am not aware of any). – Horst Walter Sep 17 '15 at 20:58
  • Widget is an example. Main idea is the paint function. You can basically reimplement paintEvent for your table. It would be much faster than gif. And because it's QPainter-based implementation - you can draw it everywhere. If you want to paint indicator on widget and then place it over another widget - you can use resizeEvent to update it's position. – RazrFalcon Sep 17 '15 at 22:49
  • Following that idea, but got some issues. Follow up created: http://stackoverflow.com/q/32653267/356726 – Horst Walter Sep 18 '15 at 13:30
  • With the paint issue solved, I use a modified version of `QProgressIndicator` painted itself into the `QTableView` viewport. – Horst Walter Sep 18 '15 at 16:54
1

QtWaitingSpinner is also an elegant solution.

Python Version here.

Matheus Torquato
  • 1,293
  • 18
  • 25