简体   繁体   English

TypeError:QPixmap.toImage():未绑定方法的第一个参数必须具有类型“ QPixmap”

[英]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.

相关问题 TypeError:QPixmap():参数 1 具有意外类型“Figure” - TypeError: QPixmap(): argument 1 has unexpected type 'Figure' TypeError:QFileDialog.history(self):未绑定方法的第一个参数必须具有类型“ QFileDialog” - TypeError: QFileDialog.history(self): first argument of unbound method must have type 'QFileDialog' Python TypeError:必须以实例作为第一个参数调用未绑定方法 - Python TypeError: unbound method must be called with instance as first argument 如何解决我的pyqt程序中的错误(未绑定方法的第一个参数必须具有“ QDialog”类型)? - How to fix error in my pyqt programm (first argument of unbound method must have type 'QDialog') ? QPixmap():参数1具有意外的类型'PngImageFile' - QPixmap(): argument 1 has unexpected type 'PngImageFile' 必须使用instance作为第一个参数调用unbound方法 - unbound method must be called with instance as first argument TypeError:未绑定方法…实例作为第一个参数 - TypeError: unbound method…instance as first argument TypeError:未绑定方法“方法名称”必须以“类名称”实例作为第一个参数来调用(取而代之的是str实例) - TypeError: unbound method 'method name' must be called with 'class name' instance as first argument (got str instance instead) TypeError:必须使用“Class name”实例作为第一个参数调用unbound方法“method name”(改为使用str实例) - TypeError: unbound method “method name” must be called with “Class name” instance as first argument (got str instance instead) TypeError:必须以DogFactory实例作为第一个参数来调用未绑定方法get_pet()(而是什么也不做) - TypeError: unbound method get_pet() must be called with DogFactory instance as first argument (got nothing instead)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM