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. Qt3 to Qt4, drawing maps with QPainterPath, Qt joining QPainterPath's together?
Forum Updated to NodeBB v4.3 + New Features

Qt3 to Qt4, drawing maps with QPainterPath, Qt joining QPainterPath's together?

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

    Hi

    I am converting an application from Qt3 to Qt4 and i am having trouble with drawing. Use to use QPointArray's to do the drawing, but now have to use QPainterPath.

    I have a 17 sided closed shape (which looks a bit like a hexagon) which display using QPainterPath on a QPainter on a QWidget. When the shape is drawn in the centre of the screen it displays ok. When I pan the shape up, down, left and right the shape moves out of the window coordinates and it is clipped and correctly displayed.
    When i move the shape so that it is half out of the screen on the left and half off the screen to the bottom it draws a line from the last clipped point at the bottom of the screen to the first clipped point that is now visible on the left hand side of the screen, i don't want it to do this!!

    In the first block of code (not the struct) it recognises that the closed polgon is broken when panned to bottom left corner and that point p2 has been clipped and a new Arc is created so ring->ArcList.size() is now 2. But somewhere it is joining all the ring->ArcLists together to become closed, and i don't know where, could drawpath be doing it?
    I have tried using moveTo() and closeSubPath() but that doesn't fix it, unless i am doing it in the wrong place?

    I would like to attached a jpeg picture but can't.

    @struct MapRing
    {
    Q_GeoPoint centre;
    double internal_radius;
    double external_radius;
    double start_angle;
    double end_angle;
    int surface_pattern;
    int thickness;
    int dash;
    int expand;
    int border_display;
    int surface_display;
    QPainterPath ExternalPoints;
    QPainterPathInternalPoints;
    QList<QPainterPath*> ArcList;
    QPainterPath SurfPoints; // Invisible outline for fill
    };@

    @ MapRing ring;
    int ArcIndex;
    bool first;
    bool p1Clipped;
    bool p2Clipped;

        QPoint start;
        QPoint end;
        QPoint p1;
        QPoint p2;
    
        QPainterPath *Arc;
    
        QPolygon polygonF;
    
    
        ring->ArcList.clear();
        
        first = true;       
    
        start.setX(internal_points.elementAt(1).x);  
        start.setY(internal_points.elementAt(1).y);  
        
        polygonF.clear();
    
    
        for(uint i = 2; i < internal_points.elementCount(); i++)
        {
          end.setX(internal_points.elementAt(i).x);
          end.setY(internal_points.elementAt(i).y);
    
          p1 = start;
          p2 = end;
    
          if(clip_rect.clipLine(p1, p2, p1Clipped, p2Clipped))
          {
    
            if(first == true)
            {
              // Start a new line  
              Arc = new QPainterPath;
              ArcIndex = 0;
              ring->ArcList.append(Arc);
              polygonF << QPoint(p1.x(), p1.y());
    
              Arc->addPolygon(polygonF);
    
              ArcIndex++;
              first = false;
            }
    
            polygonF << QPoint(p2.x(), p2.y());
            Arc->addPolygon(polygonF);
    
            ArcIndex++;
    
            if(p2Clipped == true)
            {
              first = true;
            }
          }
          start = end;
         }
         @         
    
         To draw the map rings to the window i do the following
    

    @ MapRing *ring;

    for(int i = 0; i < RingList.size(); ++i)
    {
      ring = RingList.at(i);
      if(ring->border_display)
      {      
        SetPenStyle(ring->dash, ring->thickness, &pen;);
        window->paint.setPen(pen);
    
        if(ring->InternalPoints.elementCount() > 2)
        {
          window->paint.drawPath(ring->InternalPoints);
        }
    
        if(ring->ExternalPoints.elementCount() > 2)
        {
          window->paint.drawPath(ring->ExternalPoints); //drawPolygon
        }
    
        qDebug("ring->ArcList.size() %d", ring->ArcList.size());
        for(int i = 0; i < ring->ArcList.size(); ++i)
        {
          if(ring->ArcList.at(i)->elementCount() > 0)
          {
            window->paint.drawPath(*ring->ArcList.at(i));//was drawPolyline(*arc); in qt3
          }
        }
      }
    

    }@

    I have been working on this for days now. I was not the original writer of the Qt3 code so am not expert in drawing.

    Thank you very much!

    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