Results 1 to 7 of 7

Thread: draw curve

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default draw curve

    Hello,

    I'm using QPainterPath to draw a curve on a QGraphicsView (this should be a graph later), and now I find it possible that I'm on a wrong way.

    Here is the result (concentrate on the blue thing):

    This is surely not what I meant.
    The black sinus dots a bit below works fine, but these are just dots, not a smooth line.
    Furthermore when I want to use the shortcut for the button, by pressing the "Alt" the image redraws the path, and I don't really understand what happens. I mean I gues by pressing Alt it redraws each item sent to the GraphichsView, but what does it draw now? The second one is this:


    Well, I'm "simply" searching for the solution, any ideas are welcome.

    this is the reimplementation of the paint function: (anyway, this was meant to have a hole in the middle, which now I find possible that it not possible with QPainterPath)
    related declarations:

    int maxDataNum;
    QPainterPath qpp;
    QPointF * qpf; ... later qpf = new QPointF[maxDataNum]; when it is set.


    Qt Code:
    1. void pathGraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. int i;
    4. for( i = 1; i < maxDataNum; i++)
    5. {
    6. if(!qpf[i-1].isNull() && !qpf[i].isNull())
    7. {
    8. qpp.quadTo(qpf[i-1],qpf[i]);
    9. }
    10.  
    11. }
    12.  
    13. painter->setBrush(Qt::blue);
    14. painter->drawPath(qpp);
    15. }
    To copy to clipboard, switch view to plain text mode 
    Szilvi

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: draw curve

    Quote Originally Posted by szisziszilvi View Post
    The black sinus dots a bit below works fine, but these are just dots, not a smooth line.
    And what do you expect to obtain with the pathGraphItem::paint() code you provided ? A blue line ? blue dots ?
    Can you show the paint method used to paint the "black sinus dots" ?

    If you want a blue line I'd say you can get rid of this :
    Qt Code:
    1. painter->setBrush(Qt::blue);
    To copy to clipboard, switch view to plain text mode 
    and replace it by
    Qt Code:
    1. QPen _pen(Qt::blue) ;
    2. _pen.setWidthF(0) ;
    3. _pen.setStyle(Qt::DotLine) ;
    4. painter->setPen(_pen);
    5. painter->setBrush(Qt::NoBrush);
    To copy to clipboard, switch view to plain text mode 


    Also, concerning the "hole in the middle", this is maybe what you are looking for :
    Qt Code:
    1. path.moveTo( firstPos ) ; // you may have forgotten this step by the way
    2. path.quadTo( posBeforeHole) ;
    3.  
    4. path.moveTo( posAfterHole ) ;
    5. path.quadTo( lastPos ) ;
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to totem for this useful post:

    szisziszilvi (21st January 2011)

  4. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: draw curve

    And what do you expect to obtain with the pathGraphItem:: paint() code you provided ?
    a simple, smooth line. I guess I chose a wrong object to derive from.

    Yes, I've forgotten that step you mentioned as I didn't find it interesting, this might be a misunderstanding point. I tryed this, AND WORKED!!!
    Anyway, it might be helpful for the others that quadTo needs two parameter, so the function now looks like this:

    Qt Code:
    1. void pathGraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. int i;
    4. for( i = 1; i < maxDataNum; i++)
    5. {
    6. if(!qpf[i-1].isNull() && !qpf[i].isNull())
    7. {
    8. qpp.moveTo(qpf[i-1]);
    9. qpp.quadTo(qpf[i-1],qpf[i]);
    10. }
    11.  
    12. }
    13. painter->setBrush(Qt::blue);
    14. painter->drawPath(qpp);
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by szisziszilvi; 21st January 2011 at 10:16.
    Szilvi

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: draw curve

    You might find that it is a whole lot easier to simply use Qwt instead of inventing your own plotting widget.

    http://qwt.sourceforge.net

  6. #5
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: draw curve

    yeah, I know, but I just could not figure out how to build that. But I would happily take someone's help to do that. I remember some strange moments which I couldn't explain, like I tried to make more than one time and although I did nothing to the project files the amount of warning messages started to reduce, but I can't remember what happened really. So maybe a real-time help could be the best. So that's how I started to build my own solution. But still it was worth as I learned a lot from this.
    Szilvi

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: draw curve

    Quote Originally Posted by szisziszilvi View Post
    yeah, I know, but I just could not figure out how to build that. But I would happily take someone's help to do that. I remember some strange moments which I couldn't explain, like I tried to make more than one time and although I did nothing to the project files the amount of warning messages started to reduce, but I can't remember what happened really. So maybe a real-time help could be the best. So that's how I started to build my own solution. But still it was worth as I learned a lot from this.
    OK, but what is more important to you? Getting your app to work and do what you want it to, or spending a lot of time writing a plotting widget that already exists? You -are- learning something, that's true, but it sounds like it is frustrating.

    Building Qwt is easy. I don't know what platform you are on, but just use the .pro file with qmake. Any of the Qwt example programs will show you how to incorporate it into your own app.

  8. #7
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: draw curve

    Quote Originally Posted by d_stranz View Post
    OK, but what is more important to you? Getting your app to work and do what you want it to, or spending a lot of time writing a plotting widget that already exists? You -are- learning something, that's true, but it sounds like it is frustrating.
    well, honestly actually both. It's rather like a game for me, not really anything annoying.

    Building Qwt is easy. I don't know what platform you are on, but just use the .pro file with qmake. Any of the Qwt example programs will show you how to incorporate it into your own app.
    XP. But I thing I will open a new thread for this topic as it is not the question of using any "qpainting" device.
    Szilvi

Similar Threads

  1. Replies: 1
    Last Post: 22nd January 2010, 14:34
  2. Replies: 1
    Last Post: 13th January 2010, 17:21
  3. Replies: 5
    Last Post: 10th October 2008, 06:44
  4. Want to draw Curve
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 12th September 2008, 07:14
  5. Wants to draw Luminious Curve
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 22:45

Bookmarks

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.