Results 1 to 2 of 2

Thread: how would you drawPolyLine that has missing segments

  1. #1
    Join Date
    Apr 2007
    Rakovnik, Czech Republic
    Thanked 3 Times in 3 Posts
    Qt products

    Default how would you drawPolyLine that has missing segments

    I have a QVector, "wellData", of QPoints that I render on a subclassed QWidget like so:

    Qt Code:
    1. void SkiggleLinePanel::paintEvent(QPaintEvent *e)
    2. {
    4. // QVector<QPoint> wellData;
    6. QPainter painter(this);
    8. painter.drawPolyline(, wellData.size());
    10. }
    To copy to clipboard, switch view to plain text mode 

    This works as expected. Suppose, however, that I have 7 QPoints with values like so:

    0 1
    2 2
    1 3
    3 -9
    7 5
    6 6
    2 3

    These are X and Y values, *except* -9 is actually a NULL data value, and this particular x,y coordinate pair should be thrown out... So instead of one longish line of 7 points, I would want 2 shorter lines of 3 points each. How to do this?

    One obvious fix: use QVector's members to find -9, then split it into 2 QVectors, and draw both of these. BUT: the actual problem involves a very long Polyline consisting of thousands of QPoints with many NULL values scattered throughout... so doing this would be very cumbersome. Are there other options here?
    Last edited by vonCZ; 6th May 2009 at 14:01.

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: how would you drawPolyLine that has missing segments

    QPainter::drawPolyline() takes an array of points and the number of points to draw so you can obtain what you want using this simple loop:

    Qt Code:
    1. QVector<QPoint> points;
    2. // fillWithData(points);
    3. //...
    4. int start = 0;
    5. for(int i=0;i<points.size();i++){
    6. QPoint pt =;
    7. if(pt.x()==-9 || pt.y()==-9){
    8. // draw from start to the current point
    9. if(start!=i){
    10. painter.drawPolyline(points.constData()+start, i-start);
    11. }
    12. start = i;
    13. }
    14. }
    15. if(start!=points.size()-1){
    16. painter.drawPolyline(points.constData()+start, points.size()-1-start);
    17. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.