[PyQt] PyQt5 fails to handle QQuickImageProvider subclassing

Julio César Gázquez julio_lists at mebamutual.com.ar
Mon Jan 9 12:18:50 GMT 2017

El 04/01/17 a las 16:17, Phil Thompson escribió:
 >> ImageProvider supports Image type but has not implemented requestImage()
 >> Seems this message comes from Qt's 
QQuickImageProvider::requestImage() implementation, so it's like the C++ 
method isn't being overridden by the PyQt's wrapper method.
 >> These methods are somewhat peculiar, as they are virtual methods 
(and specifically meant to be subclassed) and have an /Out/ parameter. 
Doing a grep on the PyQt sources I see this only happens in two places 
outside this class. Maybe the wrapper for the virtual method lacks the 
/Out/ parameter?
 > Try it, just pip install the latest version into a venv.
No, I'm afraid it doesn't work even with 5.7.1 (via pip install on 
Ubuntu Xenial):

julio at marte:~/devel/test$ python3 test.py
ImageProvider supports Image type but has not implemented requestImage()
file:///home/julio/devel/test/test.qml:3:1: QML Image: Failed to get 
image from provider: image://images/any.jpg

 > Otherwise I would need a short complete example that demonstrates the 
Minimal test example below.


from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtGui import QGuiApplication, QImage
from PyQt5.QtQuick import QQuickView, QQuickImageProvider

class ImageProvider(QQuickImageProvider):

      def __init__(self):

      def requestImage(self, id_, requestedSize):
          """ Just a red image """
          image = QImage(requestedSize.width(), requestedSize.height())
          return image, requestedSize

class Application(QGuiApplication):

      def __init__(self, argv):
          self._view = QQuickView()
          self._view.engine().addImageProvider("images", ImageProvider())

if __name__ == '__main__':
      app = Application([])


import QtQuick 2.1

Image {
      width: 400
      height: 300
      source: "image://images/any.jpg"


Greetings, Julio.

PyQt mailing list    PyQt at riverbankcomputing.com

More information about the PyQt mailing list