You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyQt5中QPixmap图片在QMainWindow重复显示的问题

PyQt5窗口背景图显示异常问题

我对PyQt5了解有限,修改一份给定脚本时遇到问题:脚本启动后本该显示带有图片背景和菜单栏的窗口,但背景图显示异常。

核心启动代码

def main():
    global window
    app = QApplication([])
    window = MainMenu()
    window.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 20:52:23