Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Painting on QML Element
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..
viewer = new QDeclarativeView(this);
test = dynamic_cast<QObject >(viewer->rootObject());
/ Changing the color & radius of qml rectangle/
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...
Have you taken a look at the "examples":http://www.developer.nokia.com/Community/Wiki/CS001627_-_Creating_a_custom_QML_element_with_Qt?
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":http://doc.qt.nokia.com/4.7-snapshot/declarative-toys-clocks-content-clock-qml.html example might be interesting for you in this case.