[英]TypeError: QPixmap.toImage(): first argument of unbound method must have type 'QPixmap'
I have a method that compare labels contents and return matches . 我有一个比较标签内容并返回匹配项的方法。 The method is : 方法是:
def get_selected_image(self):
if self.labelDisplayBigImage.pixmap() is None:
return False
first_image = QtGui.QPixmap.toImage(self.labelDisplayBigImage.pixmap())
selectable_images = [self.labelDisplayImage1, self.labelDisplayImage2, self.labelDisplayImage3,
self.labelDisplayImage4, self.labelDisplayImage5, self.labelDisplayImage6,
self.labelDisplayImage7, self.labelDisplayImage8]
for i in range(len(selectable_images)):
second_image = QtGui.QPixmap.toImage(selectable_images[i].pixmap())
if first_image == second_image:
return selectable_images[i].pixmap()
But got an error TypeError: QPixmap.toImage(): first argument of unbound method must have type 'QPixmap'
. 但出现错误TypeError: QPixmap.toImage(): first argument of unbound method must have type 'QPixmap'
。 So what is the problem ? 那是什么问题呢?
To use the "toImage" method you first have to instantiate the Qpixmap class to an object. 要使用“ toImage”方法,您首先必须实例化一个对象的Qpixmap类。 See http://python.6.x6.nabble.com/QPixmap-loadFromData-td5003372.html 参见http://python.6.x6.nabble.com/QPixmap-loadFromData-td5003372.html
In the example "loadfromdata" is used instead of "toImage", but the principle is the same. 在示例中,使用“ loadfromdata”代替“ toImage”,但是原理是相同的。
The xxx.pixmap()
methods you are using already return constructed QPixmap
s. 您正在使用的xxx.pixmap()
方法已经返回了构造的QPixmap
。 Instead of trying to use the QPixmap.toImage(xxx.pixmap())
, just use xxx.pixmap().toImage()
. 与其尝试使用QPixmap.toImage(xxx.pixmap())
, xxx.pixmap().toImage()
使用xxx.pixmap().toImage()
。
In your case that would be self.labelDisplayBigImage.pixmap().toImage()
and selectable_images[i].pixmap().toImage()
. 在您的情况下,这将是self.labelDisplayBigImage.pixmap().toImage()
和selectable_images[i].pixmap().toImage()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.