Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyside:按按钮更改QPixmap图像_Python_Image_Pyside_Maya_Qpixmap - Fatal编程技术网

Python Pyside:按按钮更改QPixmap图像

Python Pyside:按按钮更改QPixmap图像,python,image,pyside,maya,qpixmap,Python,Image,Pyside,Maya,Qpixmap,我正在使用pyside在maya中制作一个工具。我能够使用QPixmap将图像添加到我的UI,并将其添加到QLabel。我试图找出如何通过按下按钮(指向一个新的图像路径)来改变图像,但我很难找到如何改变图像的方法 self.pix = QtGui.QPixmap(image_path) self.lbl = QtWidgets.QLabel() self.lbl.setPixmap(self.pix) pic_layout.addWidget(self.lbl) 添加按钮: self.butt

我正在使用pyside在maya中制作一个工具。我能够使用QPixmap将图像添加到我的UI,并将其添加到QLabel。我试图找出如何通过按下按钮(指向一个新的图像路径)来改变图像,但我很难找到如何改变图像的方法

self.pix = QtGui.QPixmap(image_path)
self.lbl = QtWidgets.QLabel()
self.lbl.setPixmap(self.pix)
pic_layout.addWidget(self.lbl)
添加按钮:

self.button = QtWidgets.QPushButton(self)
订阅已单击的事件:

self.button.clicked.connect(self.button_clicked)
添加单击处理程序:

def button_clicked(self, *args):
    pixmap = QtGui.QPixmap(new_image_path)
    self.lbl.setPixmap(pixmap)

new\u image\u path
这里是新图像的路径

您可以使用QPixmap对象的加载方法

    self.pix = QtGui.QPixmap(image_path)
    self.lbl = QtWidgets.QLabel()
    self.lbl.setPixmap(self.pix)
    
    self.button = QPushButton('Change Image')
    self.button.clicked.connect(self.changeImageHandler)
    
    
    pic_layout.addWidget(self.lbl)

def changeImageHandler(self):
    self.pix.load(new_image_path)
    self.lbl.setPixmap(self.pix)