2

The code below is a simple Python code with PyQt5 to display a GIF. I have two monitors, one is an imac 5k, and the other one is a QHD monitor. It is difficult to understand the CPU usage difference between the situations that run the Python file on different monitors. Even when I make the PyQt window full screen, the CPU usage becomes much higher. Why does this happen?

from PyQt5.QtWidgets import QApplication, QDesktopWidget, QMainWindow, QLabel
from PyQt5 import QtGui
from PyQt5.QtCore import QTimer
import sys

class gifplayer(QMainWindow):
    def __init__(self):
        super(gifplayer, self).__init__()

        self.mainwidget = QMainWindow(self)
        self.setFixedSize(480, 330)
        self.center()

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.play)
        self.timer.start(2650)

        self.player = QLabel(self)
        self.movie = QtGui.QMovie("./test.gif")
        self.player.setMovie(self.movie)
        self.player.setGeometry(0, 0, 480, 330)
        self.movie.start()
        self.show()

    def play(self):
        self.movie.start()  # those lines

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)


app = QApplication(sys.argv)
ex = gifplayer()
sys.exit(app.exec_())
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Fred kim
  • 21
  • 2
  • How are you controlling which monitor the application comes up on? Does QDesktopWidget think you have multiple screens or just one virtualDesktop? I've seen stuff on multimonitor setups where applications seem to run faster on whichever monitor they start on, but slow down when dragged to the other monitor. But if they were started on the other monitor they run fine. If it's something like that, it might help to connect to a screenChanged signal (from QWindow?) and reconstruct your player and/or movie objects when it changes. – timday Nov 08 '17 at 00:14

0 Answers0