Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QDeclarativeImageProvider does not load image in container
Forum Updated to NodeBB v4.3 + New Features

QDeclarativeImageProvider does not load image in container

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vaychick
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vaychick
      wrote on last edited by
      #2

      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"
      }
      }@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved