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. Subclassing QML Image item
Forum Updated to NodeBB v4.3 + New Features

Subclassing QML Image item

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.5k 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.
  • R Offline
    R Offline
    redkite
    wrote on 20 Apr 2012, 20:53 last edited by
    #1

    Hello,

    I'm trying to create a QML Image item from a C++ class, for dynamically adding image into a QDeclarativeView.
    I found that I need to herit from QDeclarativeItem and to implement paint(...).

    Isn't it possible to directly use/herit the QML item "Image":http://doc-snapshot.qt-project.org/4.8/qml-image.html" instead? Like this, I would only need to set the property "source" by my self, and the painting, the scaling, the fitting, ... will be managed automatically like "Image":http://doc-snapshot.qt-project.org/4.8/qml-image.html" item from QML component did?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on 23 Apr 2012, 03:00 last edited by
      #2

      Hi,

      It isn't possible to use or inherit QDeclarativeImage directly from C++ (it is a private class). One option for creating and manipulating Image elements from C++ is the following:

      @
      QQmlEngine engine;
      QQmlComponent component(&engine);
      component.setData("import QtQuick 1.0;\nImage {}", QUrl());
      QObject *object = component.create();
      @

      You could then set the source either via QObject::setProperty(), or by manipulating the string passed to setData().

      Regards,
      Michael

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redkite
        wrote on 23 Apr 2012, 06:54 last edited by
        #3

        Thanks for the reply,

        it was already what I did (I suppose you mean QDeclarativeComponent in Qt 4.8.1), except that I was loading a nearly empty QML file :
        @QDeclarativeComponent component(engine, QUrl::fromLocalFile("myimage.qml"));@

        But it's still not allowing me to get a C++ class like MyImage which would also be a QDeclarativeImage.

        I was needing a direct inherit from my C++ class to the declarative class for easily founding my C++ class from the parent item of an other QML item using findChild.

        1 Reply Last reply
        0

        1/3

        20 Apr 2012, 20:53

        • Login

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