Reputation: 529
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'
. So what is the problem ?
Upvotes: 0
Views: 1736
Reputation: 11849
The xxx.pixmap()
methods you are using already return constructed QPixmap
s. Instead of trying to use the QPixmap.toImage(xxx.pixmap())
, just use xxx.pixmap().toImage()
.
In your case that would be self.labelDisplayBigImage.pixmap().toImage()
and selectable_images[i].pixmap().toImage()
.
Upvotes: 0
Reputation: 528
To use the "toImage" method you first have to instantiate the Qpixmap class to an object. See 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.
Upvotes: 1