QDeclarativeImageProvider does not load image in container



  • Hello.

    @class QMLImageProvider : public QObject, public QDeclarativeImageProvider
    {
    Q_OBJECT
    private:
    QPixmap front;
    QPixmap back;

    public:
    explicit QMLImageProvider();
    QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
    };@

    implementation

    @QMLImageProvider::QMLImageProvider() : QObject(0),
    QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap) {}

    QPixmap QMLImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) {
    return QPixmap(QString("QML/screen1.png"));
    }@

    registration:

    @screenArea = new QDeclarativeView(wgScreenArea);
    qmlImageProvider = new QMLImageProvider();
    screenArea->engine()->addImageProvider(GlobalVars::imageProviderID, qmlImageProvider);

    screenArea->setSource(QUrl::fromLocalFile("QML/screen.qml"));
    screenArea->setResizeMode(QDeclarativeView::SizeRootObjectToView);@
    

    QML script:

    @ Image {
    id: backImage
    source: "image://imageprovider/frontimage"
    }@
    works fine, but doesn't work with Column or another container
    @Column {

    Image {
            id: backImage
            source: "image://imageprovider/frontimage"
        }
    

    }@

    whereas
    @Column {

    Image {
            id: backImage
            source: "screen1.png"
        }
    

    }@
    OK.
    Why?

    P.S. Sorry for my english.



  • I found answer on stackoverflow: "Columns get a bit funny with items that don't declare their width and height" from funkybro.

    @Column {
    id:screenImage
    Image {
    id: backImage
    width: screenImage.width
    height: screenImage.height
    source: "image://imageprovider/backimage"
    }
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.