Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Painting on QML Element
Forum Updated to NodeBB v4.3 + New Features

Painting on QML Element

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 4.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mammamia
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mammamia
      wrote on last edited by
      #2

      @QmlViewer::QmlViewer(QWidget parent)
      :QWidget(parent)
      {
      viewer = new QDeclarativeView(this);
      viewer->setSource(QUrl("qml/transfer/main.qml"));
      viewer->setGeometry(0,0,200,200);
      test = dynamic_cast<QObject >(viewer->rootObject());
      ....
      }
      /
      Changing the color & radius of qml rectangle
      /
      void QmlViewer::changecolor()
      {
      QObject *text = test->findChild<QObject *>(QString("myText"));
      text->setProperty("text","Clicked");
      QObject *rect = test->findChild<QObject *>(QString("rects"));
      rect->setProperty("color","skyblue");
      rect->setProperty("radius",10);
      }
      @

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        Have you taken a look at the "examples":http://www.developer.nokia.com/Community/Wiki/CS001627_-_Creating_a_custom_QML_element_with_Qt?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mammamia
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mammamia
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved