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.

    svgitem.h:
    @#ifndef SVGIMAGE_H
    #define SVGIMAGE_H

    #include <QDeclarativeItem>

    class QGraphicsSvgItem;

    class SvgImage : public QDeclarativeItem
    {
    Q_OBJECT

    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;
    

    public:
    SvgImage( QDeclarativeItem *parent = 0 );

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

    signals:
    void sourceChanged();
    void elementIdChanged();

    };

    QML_DECLARE_TYPE( SvgImage )

    #endif //SVGIMAGE_H
    @

    svgitem.cpp:
    @#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();
    

    }
    @

    Use:
    @SvgImage{
    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
 

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