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. drawing a partial QPainterPath based on percentages?
Qt 6.11 is out! See what's new in the release blog

drawing a partial QPainterPath based on percentages?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.4k 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.
  • J Offline
    J Offline
    jdlyga
    wrote on last edited by
    #1

    I'm trying to draw a partial QPainterPath. I added 2 arcs connected by a line segment to a QPainterPath. What I'm trying to do is to treat the QPainterPath as a singular object, and only draw certain parts of that path based on percentages. For example, drawing between 0.2 and 0.8.

    Here's what I'm aiming to do:
    reduced

    Does anyone know of a way I can accomplish this? It doesn't look like QPainterPath supports this, but there must be some way.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rondog
      wrote on last edited by Rondog
      #2

      I am not sure I fully understand what you are asking so if this comment seems off then I guess I don't understand.

      I believe what you have is some sort of path where the first point is considered to be zero and the last point is one. The number of points inside this path and the relative spacing is not important.

      The best way to handl this is to use a spline of some sort. The spline doesn't need to smooth the data but can treat it as a polyline. You put all your points that describe this shape into a spline where the path is described as a 'u' value that typically has a range of 0 to 1 (sometimes -1 to 1).

      To draw the path you would have something like this:

      TSpline my_spline(point_data_describing_full_shape);
      TPoint point;
      
      point = my_spline.evaluate(0.);   // returns the first point
      point = my_spline.evaluate(1.);   // returns the last point
      point = my_spline.evaluate(0.2);  // returns a point that is at 20% along the full path length.
      point = my_spline.evaluate(0.8);  // returns a point that is at 80% along the full path length.
      

      If using splines it may be important to space the input point data evenly. If you bunch up points in certain areas, depending on the spline math, you might find the sections are compressed relative the the number of points in the area (so 0.25 doesn't return 25% of the actual length). I always try to space out the input points evenly to minimize this problem.

      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