Painting on QML Element

  • Hii....
    I have created my own QML element and i am able to implement it inside a class... I will be setting some properties of this QML element from my C++ class... That is working fine... But i need to make some drawings on the QML element which i cannot do in the QML file directly... So i need to implement PaintEvent in my class to do that... I tried to implement PaintEvent, but i am unable draw over my QML element... Hope you understand my problem... Please give me a solution.....I used QDeclarativeView to load my QML inside the Class.... Thats working fine..

    Please help...

    Thank u...

  • @QmlViewer::QmlViewer(QWidget parent)
    viewer = new QDeclarativeView(this);
    test = dynamic_cast<QObject >(viewer->rootObject());
    Changing the color & radius of qml rectangle
    void QmlViewer::changecolor()
    QObject *text = test->findChild<QObject *>(QString("myText"));
    QObject *rect = test->findChild<QObject *>(QString("rects"));

    Along with this code i need to Paint on this qml element.. I need to know how can i do that...

  • Ya i looked at that... But i dont need a class to create custom component... What my aim is to implement design in qml + functionality and control in my C++ class... Whenever am creating object for my c++ class i should able to place that qml element on aother widget or window with all properties...hope you understand my requirement...

  • Actually, I don't, but you do need to create a custom component if you want to do custom painting.

    Can you wrap your requirement in a concrecte example? This would help us understanding you greatly.

  • i am trying to to create a custom configurable speedometer widget which i should be able to put in another work space(another widget/window)... Background and needle will be image that i can set inside the qml itself... And i need to draw circular dial inside that meter and should be able to set all numbers and span of meter Ticks and meter name... These things( drawing the dial, Tick marks, rotation ) everything i need to do from that c++ class. I will be having methods to set these properties... The main aim is whenever i am creating an object for that class i should get a configurable meter..... this is my requirement.....

  • If you want to do your painting in C++ you will have to subclass QDeclarativeItem (resp. QQuickItem when you are on Qt 5 / QtQuick 2.0); see the example I've mentioned.

    Another option would be creating the item entirely in QML; the "QML clock": example might be interesting for you in this case.

Log in to reply

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