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. How to draw interactive geometrical shapes, that will allow me to drag their corners?
Forum Updated to NodeBB v4.3 + New Features

How to draw interactive geometrical shapes, that will allow me to drag their corners?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 929 Views 2 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.
  • Petross404_Petros SP Offline
    Petross404_Petros SP Offline
    Petross404_Petros S
    wrote on last edited by Petross404_Petros S
    #1

    Happy New Year fellows!

    I want to create a calculator like this, so the user can enter some values for 2 lines and their angle for a triangle and the program will calculate and report back other info.

    It's not that difficult to do this with a QGraphicsScene pbject but I also want to drag the edges so that I create my own triangle. After that the spinboxes will be updated with the new data and points and new calculations will be triggered.

    So my questions are the following:

    1. Can I drag a shape/line/edge/any geometrical entity on a QGraphicsScene or anywhere else?

    2. Can I somehow create a grid that will understand the concept of points and give me the ability to calculate the length of that line, or calculate the area of a triangle?

    Is there an API for this or do I have to do the complex mathematics myself?

    O 1 Reply Last reply
    0
    • Petross404_Petros SP Petross404_Petros S

      Happy New Year fellows!

      I want to create a calculator like this, so the user can enter some values for 2 lines and their angle for a triangle and the program will calculate and report back other info.

      It's not that difficult to do this with a QGraphicsScene pbject but I also want to drag the edges so that I create my own triangle. After that the spinboxes will be updated with the new data and points and new calculations will be triggered.

      So my questions are the following:

      1. Can I drag a shape/line/edge/any geometrical entity on a QGraphicsScene or anywhere else?

      2. Can I somehow create a grid that will understand the concept of points and give me the ability to calculate the length of that line, or calculate the area of a triangle?

      Is there an API for this or do I have to do the complex mathematics myself?

      O Offline
      O Offline
      ofmrew
      wrote on last edited by
      #2

      @Petross404_Petros-S To drag the corner points of a triangle, I would suggest that you find the closest corner point to the mouse point. Move the mouse point to that location and let the user drag that point. Recall that distance can be found by qSqrt(QPointF::dotProduct(p1, p2)).

      O 1 Reply Last reply
      1
      • O ofmrew

        @Petross404_Petros-S To drag the corner points of a triangle, I would suggest that you find the closest corner point to the mouse point. Move the mouse point to that location and let the user drag that point. Recall that distance can be found by qSqrt(QPointF::dotProduct(p1, p2)).

        O Offline
        O Offline
        ofmrew
        wrote on last edited by
        #3

        @ofmrew I forgot to mention that if you are using QPainterpath objects, then you will need to the the elements that form the path. You can get the points you need from the elements.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          1. Yes you can but you have to handle the mouse event yourself.
          2. Isn't that the role of your shape ?

          You can pick the basics on how to do it from this stackoverflow question. Even though it's in python you can pretty easily translate it back to C++.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Petross404_Petros SP Offline
            Petross404_Petros SP Offline
            Petross404_Petros S
            wrote on last edited by
            #5

            Thank you both for those hints!

            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