Qml svg element id

  • Hi all!

    How can I set element id of svg image in QML?

  • So, I writed an own declarative item and now works.

    @#ifndef SVGIMAGE_H
    #define SVGIMAGE_H

    #include <QDeclarativeItem>

    class QGraphicsSvgItem;

    class SvgImage : public QDeclarativeItem

    Q_PROPERTY( QString source READ source WRITE setSource NOTIFY sourceChanged );
    Q_PROPERTY( QString elementId READ elementId WRITE setElementId NOTIFY elementIdChanged );
    QString mSource;
    QString mElementId;
    QGraphicsSvgItem* mSvgItem;

    SvgImage( QDeclarativeItem *parent = 0 );

    QString source(){ return mSource; }
    QString elementId(){ return mElementId; }
    void setSource( QString source );
    void setElementId( QString elementId );

    void sourceChanged();
    void elementIdChanged();


    QML_DECLARE_TYPE( SvgImage )

    #endif //SVGIMAGE_H

    @#include <QSvgRenderer>
    #include <QGraphicsSvgItem>
    #include "svgimage.h"

    SvgImage::SvgImage( QDeclarativeItem *parent ) :
    QDeclarativeItem( parent )
    mSvgItem = new QGraphicsSvgItem( this );

    void SvgImage::setSource( QString source )
    mSource = source;

    mSvgItem->setSharedRenderer( new QSvgRenderer( mSource ) );
    emit sourceChanged();


    void SvgImage::setElementId( QString elementId )
    mElementId = elementId;

    mSvgItem->setElementId( mElementId );
    emit elementIdChanged();


    id: deck
    source: "william-tell.svgz"
    elementId: "back"

    And the tutorial "here":http://www.developer.nokia.com/Community/Wiki/Creating_a_custom_QML_element_with_Qt

Log in to reply