Pergunta

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?

Declaration:

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);

P.S. Sorry for my english.

~SOLVED~

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

It Works! Thank you very much!

Foi útil?

Solução

Possibly that the Image using the ImageProvider doesn't declare its width and height correctly? Columns get a bit funny with items that don't declare their width and height. Try hard coding the width and height in your Image in your second example and it should work.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top