SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PyQt4.QtCore import QSize
  2. from PyQt4.QtGui import QApplication, QLabel, QMovie, QPainter, QFontMetrics
  3.  
  4. class QTextMovieLabel(QLabel):
  5.     def __init__(self, text, fileName):
  6.         QLabel.__init__(self)
  7.         self._text = text
  8.         m = QMovie(fileName)
  9.         m.start()
  10.         self.setMovie(m)
  11.  
  12.     def setMovie(self, movie):
  13.         QLabel.setMovie(self, movie)
  14.         s=movie.currentImage().size()
  15.         self._movieWidth = s.width()
  16.         self._movieHeight = s.height()
  17.  
  18.     def paintEvent(self, evt):
  19.         QLabel.paintEvent(self, evt)
  20.         p = QPainter(self)
  21.         p.setFont(self.font())
  22.         x = self._movieWidth + 6
  23.         y = (self.height() + p.fontMetrics().xHeight()) / 2
  24.         p.drawText(x, y, self._text)
  25.         p.end()
  26.  
  27.     def sizeHint(self):
  28.         fm = QFontMetrics(self.font())
  29.         return QSize(self._movieWidth + 6 + fm.width(self._text),
  30.                 self._movieHeight)
  31.  
  32.     def setText(self, text):
  33.         self._text = text
  34.  
  35. if __name__ == '__main__':
  36.     import sys
  37.     app = QApplication(sys.argv)
  38.     l = QTextMovieLabel('Loading...', 'loading.gif')
  39.     l.show()
  40.     app.exec_()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top