Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter -draw a diagram and get data from it
QtWS25 Last Chance

QPainter -draw a diagram and get data from it

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.0k Views
  • 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 Offline
    V Offline
    Veaceslav
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        amban
        wrote on last edited by
        #3

        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
        0
        • V Offline
          V Offline
          Veaceslav
          wrote on last edited by
          #4

          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
          0
          • V Offline
            V Offline
            Veaceslav
            wrote on last edited by
            #5

            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
            0
            • D Offline
              D Offline
              DerManu
              wrote on last edited by
              #6

              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
              0
              • V Offline
                V Offline
                Veaceslav
                wrote on last edited by
                #7

                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
                0

                • Login

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