PyQt5中QPixmap图片在QMainWindow重复显示的问题
PyQt5窗口背景图显示异常问题
我对PyQt5了解有限,修改一份给定脚本时遇到问题:脚本启动后本该显示带有图片背景和菜单栏的窗口,但背景图显示异常。
核心启动代码
def main(): global window app = QApplication([]) window = MainMenu() window.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
MainMenu类定义
class MainMenu(QMainWindow): def __init__(self): super(MainMenu, self).__init__() self.window() layout = self.frame_layout() self.create_menubar() def window(self): screen_width, screen_height = pyautogui.size() self.setGeometry(0, 0, screen_width - 25, screen_height - 180) self.showMaximized() startup_background(self)
调色板方式设置背景图代码
pixmap = QPixmap(background.png).scaled(window.width(), window.height(),QtCore.Qt.KeepAspectRatio) palette = QPalette() palette.setBrush(QPalette.Background, QBrush(pixmap)) window.setPalette(palette)
使用该代码时,背景图(多时间序列图)出现重复显示,右侧被截断。
尝试的QLabel替代方案
label = QLabel(window) label.setPixmap(pixmap)
但这种方法没有任何效果。
内容的提问来源于stack exchange,提问作者fishbacp
相关产品推荐
相关产品推荐

