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. QPainterPath painting reverse?
Forum Updated to NodeBB v4.3 + New Features

QPainterPath painting reverse?

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

    Hi.
    This is my setup: a QGraphicsView in the form, a function that fills a QPointF vector with simple points (a normally ascending X with different Y values for each X) and then a function that prints those numbers:
    @ QGraphicsScene *scene = new QGraphicsScene();
    QPainterPath linePath;
    for(int i=0; i<m_qvPoints.size(); i++)
    {
    linePath.lineTo(m_qvPoints[i].x(), m_qvPoints[i].y());
    }
    scene->addPath(linePath, QPen("blue"), QBrush("white", Qt::NoBrush));
    ui->graphicsView->setScene(scene);
    ui->graphicsView->show();@

    And this is how I fill the vector (it's inside a for loop):
    @m_qvPoints.append(QPointF(giro, m_Bankn));@

    But i encounter two unexpected/unwanted results:

    1. The graphic is "reversed". This means that it seems to be printing the elements from the end to the beginning (so when the graphic should be descendant, it appears ascendant). I've checked manually the vector where the points are and it seems to be OK. Weird thing is that i've tried printing them reversed like this:
      @for(int i=m_qvPoints.size(); i>0; i--)@

    But the graphic is drawn exactly the same! :O

    1. There's a straight line appearing from the end to the beginning which has nothing to do with the function itself :\

    Here's a couple of screen caps:

    http://i.imgur.com/cZPux.png

    http://i.imgur.com/xOR0Q.png

    Any ideas? Thanks!

    PS: By the way, how can I easily add some reference frame like coordinates to orient myself when looking at the graph?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Valiance
      wrote on last edited by
      #2

      I'm wondering if your figure is not 'upside-down' rather than backwards... The usual default coordinate system will have y increasing down the screen rather than up like you would probably be used to. If you are pumping data points directly into the QPainterPath then, you might be able to just invert y coordinates you pass to the painterPath functions. (There may be something you can do with the items transformation, i.e. a vertical reflection or something, but this way is probably the quickest).

      Also, the first thing that you probably want to do is call moveTo() on the painterPath to start the path at the first point of your dataset (and then start your loop at i = 1).

      i.e.

      @linePath.moveTo(m_qvPoints.at(0).x(), -m_qvPoints.at(0).y();

      for(int i=1; i<m_qvPoints.size(); i++)
      {
      linePath.lineTo(m_qvPoints[i].x(), -m_qvPoints[i].y());
      }
      @

      As for 'drawing it backwards' it makes sense that you're ending up with the same figure because it's equivalent to tracing a line with your finger from left to right or right to left.... the traced path is the exact same. The only way you're going to change the way things are drawn is by changing the x/y coordinates that are being passed into the path -> like negating the y-coordinates in the snippet above.

      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