maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   PyQt5 and QQuickImageProvider (https://talk.maemo.org/showthread.php?t=91519)

xerxes2 2013-10-04 13:51

PyQt5 and QQuickImageProvider
 
So pyqt-5.1 was just relased and it works pretty good so far with qt-5.1.1 but I've got one problem that I can't seem to fix. The QQuickImageProvider requestPixmap method gives an error from qml:

Code:

from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5 import QtQml
from PyQt5 import QtQuick

class ImageProviderGUI(QtCore.QObject):
    def __init__(self):
        QtCore.QObject.__init__(self)
        self.app = QtWidgets.QApplication(["ImageProvider"])
        self.view = QtQuick.QQuickView()
        self.view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)
        self.context = self.view.rootContext()
        engine = self.context.engine()
        self.image_provider = ImageProvider()
        engine.addImageProvider("cover", self.image_provider)
        self.view.setSource(QtCore.QUrl("test.qml"))
        self.view.show()
        self.app.exec_()

class ImageProvider(QtQuick.QQuickImageProvider):
    def __init__(self):
        QtQuick.QQuickImageProvider.__init__(self, QtQuick.QQuickImageProvider.Pixmap)
   
    def requestPixmap(self, id, size):
        pixmap = QtGui.QPixmap(100, 100)
        pixmap.fill(QtGui.QColor(id))
        return pixmap
   
ImageProviderGUI()

Code:

import QtQuick 2.0
//import QtQuick 1.1

Image {
        source: "image://cover/red"
}

Code:

TypeError: invalid result type from ImageProvider.requestPixmap()
file:///home/xerxes2/test.qml:5:1: QML Image: Failed to get image from provider: image://cover/red

The same thing works just fine with Pyside:
Code:

from PySide import QtCore
from PySide import QtGui
from PySide import QtDeclarative

class ImageProviderGUI(QtCore.QObject):
    def __init__(self):
        QtCore.QObject.__init__(self)
        self.app = QtGui.QApplication(["ImageProvider"])
        self.view = QtDeclarative.QDeclarativeView()
        self.view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView)
        self.context = self.view.rootContext()
        engine = self.context.engine()
        self.image_provider = ImageProvider()
        engine.addImageProvider("cover", self.image_provider)
        self.view.setSource("test.qml")
        self.view.show()
        self.app.exec_()

class ImageProvider(QtDeclarative.QDeclarativeImageProvider):
    def __init__(self):
        QtDeclarative.QDeclarativeImageProvider.__init__(self, QtDeclarative.QDeclarativeImageProvider.Pixmap)
   
    def requestPixmap(self, id, size, requestedsize):
        pixmap = QtGui.QPixmap(100, 100)
        pixmap.fill(QtGui.QColor(id))
        return pixmap
   
ImageProviderGUI()

Any help appreciated. If it's a bug outside of my own code it would be nice to figure out if it's in qt or pyqt too.

xerxes2 2013-10-07 13:47

Re: PyQt5 and QQuickImageProvider
 
Got a response on the pyqt mailing list:
http://www.riverbankcomputing.com/pi...er/033280.html

So now Panucci seems to be 100% working on pyqt5. :)


All times are GMT. The time now is 23:32.

vBulletin® Version 3.8.8