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. Draggable Bezier curve points with QPainterPath in QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

Draggable Bezier curve points with QPainterPath in QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k 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
    mfeemster
    wrote on last edited by
    #1

    I want to draw a Bezier curve on a QGraphicsView, and have the 2 middle control points be draggable. Here's where I'm at now:

    -I have a class called CurvesGraphicsView that derives from QGraphicsView.
    -I can create a QGraphicsEllipseItem by calling addEllipse() in the CurvesGraphicsView constructor.
    -This ellipse is be draggable without any extra code on my part (nice!).

    My problem is, how do I get this draggable point to be assigned to the curve point, and have the curve draw properly?

    From what I see, this is impossible because a curve can only be drawn once per object construction. Example:

    To draw, you must do this every time in mouseMoveEvent():

    @
    QRectF rect = scene()->sceneRect();
    QPainterPath path(rect.bottomLeft());//Must construct a new one every time, they are not reusable.

    m_MousePos = mapToScene(e->x(), e->y());
    path.cubicTo(m_MousePos, m_MousePos, rect.topRight());
    scene()->clear();//Removes the previous curve, but also removes the ellipse, which is not what we want to do.
    scene()->addPath(path);@

    -It cannot be kept as a member and drawn with new points a second time.
    -This requires clearing of the scene each time you want to draw a curve.
    -Clearing the scene removes the original ellipse item, defeating the purpose.

    Can anyone provide an example that shows how to draw two ellipses on the control points of the Bezier curve, and update that curve in response to a drag event on either of the points? I have a very simple need, yet despite pages and pages of documentation, cannot figure out how to implement it.

    Thanks.

    github.com/mfeemster/fractorium/wiki

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on last edited by
      #2

      Maybe this is kind of what you want.

      http://qt-project.org/doc/qt-4.8/demos-pathstroke.html

      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