Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMovie inside frame



  • How I can put a GIF with Qmovie into frame_2 and
    set a size to the GIF?

    self.frame_2 = QFrame(self.centralwidget)
    self.frame_2.setObjectName(u"frame_2")
    self.frame_2.setGeometry(QRect(230, 60, 271, 261))
    self.frame_2.setStyleSheet(u"background-color: rgb(255, 0, 0);")
    self.frame_2.setFrameShape(QFrame.StyledPanel)
    self.frame_2.setFrameShadow(QFrame.Raised)
    
    

  • Banned

    @Black-Cat had you supplied a MRE (Minimal Reproducible Example) that would have sped things up. Further as it stands this MUC is my rendition of something like what you are trying to do and it may or may not work for you since I have no idea of what version of Python-Qt you are attempting to use

    from PyQt5.QtCore    import pyqtSlot
    from PyQt5.QtGui     import QMovie
    from PyQt5.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout
    from PyQt5.QtWidgets import QWidget, QFrame, QLabel, QPushButton
    
    class GifFrame(QLabel):
        def __init__(self, parent):
            QLabel.__init__(self)
            self.Parent = parent
    
            self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)
            self.setLineWidth(10)
            self.setMidLineWidth(10)
            self.setStyleSheet('background-color: rgb(255, 0, 0)')
    
            self.DaGif = QMovie("C:/Images/Gifs/giphy.gif")
            
            self.lblGifHldr = QLabel()
            self.lblGifHldr.setMovie(self.DaGif)
    
            self.DaGif.start()
            self.Parent.IsOn = True
    
            HBox = QHBoxLayout()
            HBox.addStretch(1)
            HBox.addWidget(self.lblGifHldr)
            HBox.addStretch(1)
            
            self.setLayout(HBox)
            
    class CenterPanel(QWidget):
        def __init__(self, parent):
            QWidget.__init__(self)
            self.Parent = parent
            self.IsOn = False
    
            self.btnQuit = QPushButton('Stop')
            self.btnQuit.clicked.connect(self.ToggleIt)
    
            HBox = QHBoxLayout()
            HBox.addStretch(1)
            HBox.addWidget(self.btnQuit)
    
            self.GifView = GifFrame(self)
    
            VBox = QVBoxLayout()
            VBox.addWidget(self.GifView)
            VBox.addLayout(HBox)
            
            self.setLayout(VBox)
    
        @pyqtSlot()
        def ToggleIt(self):
            if self.IsOn:
                self.IsOn = False
                self.btnQuit.setText('Start')
                self.GifView.DaGif.stop()
            else:
                self.IsOn = True
                self.btnQuit.setText('Stop')
                self.GifView.DaGif.start()
    
    class MainUI(QMainWindow):
        def __init__(self):
            QMainWindow.__init__(self)
            self.setWindowTitle('Framed It')
            
            WinLeft = 550; WinTop = 250; WinWidth = 550; WinHigh = 550
            self.setGeometry(WinLeft, WinTop, WinWidth, WinHigh)
    
            self.CenterPane = CenterPanel(self)
            self.setCentralWidget(self.CenterPane)
    
    if __name__ == "__main__":
        MainEventHandler = QApplication([])
    
        MainApplication = MainUI()
        MainApplication.show()
        
        MainEventHandler.exec()
    


  • Thanks :)


Log in to reply