May 11, 2012

Arun P K Arun P K
Lab Rat
35 posts

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…

6 replies

May 11, 2012

Arun P K Arun P K
Lab Rat
35 posts

  1. QmlViewer::QmlViewer(QWidget *parent)
  2.                  :QWidget(parent)
  3. {    
  4.     viewer = new QDeclarativeView(this);
  5.     viewer->setSource(QUrl("qml/transfer/main.qml"));
  6.     viewer->setGeometry(0,0,200,200);
  7.     test = dynamic_cast<QObject *>(viewer->rootObject());
  8. ....
  9. }
  10. /* Changing the color & radius of qml rectangle*/
  11. void QmlViewer::changecolor()
  12. {
  13.     QObject *text = test->findChild<QObject *>(QString("myText"));
  14.     text->setProperty("text","Clicked");
  15.     QObject *rect = test->findChild<QObject *>(QString("rects"));
  16.     rect->setProperty("color","skyblue");
  17.     rect->setProperty("radius",10);
  18. }

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

May 11, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Have you taken a look at the examples [developer.nokia.com]?

May 11, 2012

Arun P K Arun P K
Lab Rat
35 posts

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…

May 11, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

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.

May 11, 2012

Arun P K Arun P K
Lab Rat
35 posts

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…..

May 11, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

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 [doc.qt.nokia.com] example might be interesting for you in this case.

 
  ‹‹ Qt Quick IVI demo is not working.      Qml/Js/Vm vs. Upgraded C++ GUI API with Bindings ››

You must log in to post a reply. Not a member yet? Register here!