Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QPainter -draw a diagram and get data from it

    General and Desktop
    4
    7
    3600
    Loading More Posts
    • 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.
    • V
      Veaceslav last edited by

      Hello,

      for my project i need draw a diagram from model, and allow the user to edit it.

      Here is an example:

      https://docs.google.com/drawings/d/1P4NYWNnNI6mGidrtuA_NF4gc90o2YzqhxRj9xlx4qNw/edit

      Rectangles will be read from model so user won't be able to add them. Circles mean input and outputs for tasks (probably also will be read from model )

      And what i need is to let user to add/delete an arrow from one circle to another and to get information about all connections in a list:

      circle1- circle 2
      circle 2- circle 4

      etc...

      This is possible to be done with QPainter?

      if yes, can you provide me with some tutorials especially the part with user drawing and getting data from image?

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        I would use the "Graphics View Framework":/doc/qt-4.8/graphicsview.html classes. You will use [[doc:QGraphicsView]] and it's friends [[doc:QGraphicsScene]] and [[doc:QGraphicsItem]] (and subclasses).

        1 Reply Last reply Reply Quote 0
        • A
          amban last edited by

          Hi,
          This example will be the best to start with - http://doc.qt.nokia.com/4.7-snapshot/graphicsview-diagramscene.html

          1 Reply Last reply Reply Quote 0
          • V
            Veaceslav last edited by

            Hmm... previous developer tried to implement something like this, but he didn't succeed.

            Now i have a piece of code that looks like that tutorial and i think I'll come back with more specific question.

            Andre, amban thanks a lot for your help :)

            1 Reply Last reply Reply Quote 0
            • V
              Veaceslav last edited by

              Hello, i came back with other question:

              I've managed to draw the rectangle with inputs:

              http://i47.tinypic.com/aln20y.png

              I used
              painter->drawEllipse(QRectF)

              Now i'm interested if i can figure out which circle was clicked.

              1 Reply Last reply Reply Quote 0
              • D
                DerManu last edited by

                A circle is clicked if the distance of the click position to the center of the circle is smaller (or equal) to the radius of the circle, e.g.
                @(click.x-circle.x)^2 + (click.y-circle.y)^2 <= circle.radius^2@

                But if I'm not mistaken, the GraphicsView-Framework should already contain a simple circle/ellipse item with hit-test etc.

                1 Reply Last reply Reply Quote 0
                • V
                  Veaceslav last edited by

                  I think it have mouse click event, but the problem is that is one custom item,

                  that contains a rectangle and 2 circles(not three different objects).

                  It's a object with boundingRect = (0,0,100,100)

                  rectangle drawn at (0,25,100,50)

                  and another 2 circles. I can save that circle's QRect in a list, but how to get pointer position inside the graphics item?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post