Results 1 to 9 of 9

Thread: Some problem with painter's fillpath() method

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Some problem with painter's fillpath() method

    I wanted to develop an application in which i want a progress bar as in the 1st attachment so that the green bar moves around the grey bar showing the progress,but for now i cannot locate the green bar properly and by writing the below code it shows me the picture in 2nd attachment while for now i want the output as of 1st attachment.

    HEADER FILE
    Qt Code:
    1. #include <QGraphicsItem>
    2. #include <QPainter>
    3. #include <QPainterPath>
    4.  
    5. class ConfirmationScene:public QGraphicsItem
    6. {
    7. public:
    8. QRectF r1;
    9.  
    10.  
    11.  
    12.  
    13. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    14. QWidget *widget);
    15. QRectF boundingRect() const;
    16.  
    17. ConfirmationScene();
    18. ~ConfirmationScene();
    19. };
    To copy to clipboard, switch view to plain text mode 

    SOURCE FILE
    Qt Code:
    1. #include "ConfirmationScene.h"
    2.  
    3. ConfirmationScene::ConfirmationScene()
    4. {
    5. r1.setRect(10,10,50,50);
    6. path.addEllipse(r1);
    7.  
    8. }
    9.  
    10. void ConfirmationScene::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    11. QWidget *widget)
    12. {
    13.  
    14. painter->setPen(QPen(QBrush(Qt::gray,Qt::SolidPattern),30,Qt::SolidLine,Qt::FlatCap,Qt::MiterJoin));
    15. painter->drawEllipse(0, 0, 200, 200);
    16.  
    17. painter->fillPath(path,QBrush(Qt::green,Qt::SolidPattern));
    18. painter->drawPath(path);
    19. }
    20. QRectF ConfirmationScene::boundingRect() const
    21. {
    22. qreal penWidth = 150;
    23. return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,20 + penWidth / 2, 20 + penWidth / 2);
    24. }
    25. ConfirmationScene::~ConfirmationScene()
    26. {
    27. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    • File Type: gif 1.GIF (3.4 KB, 10 views)
    • File Type: gif 2.GIF (3.6 KB, 9 views)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some problem with painter's fillpath() method

    Quote Originally Posted by salmanmanekia View Post
    it shows me the picture in 2nd attachment while for now i want the output as of 1st attachment.
    Do I understand correctly, that you want to draw that a green circle and gray ellipse, but you get only the green circle?

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problem with painter's fillpath() method

    actually i want a green circle in the elliptical grey circle...the green circle would move around the grey circle as a progress bar..but its the next thing...for now my problem 'WAS' that i had a green circle around a grey elliptical circle but green circle was surrounded by grey circle as shown in 2nd attachment ,which was undesirable...any ways i have found the solution of this problem by using the save() and restore() method...if you have any other idea /suggestion ,i would always welcome it...THANKS

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some problem with painter's fillpath() method

    Quote Originally Posted by salmanmanekia View Post
    for now my problem 'WAS' that i had a green circle around a grey elliptical circle but green circle was surrounded by grey circle as shown in 2nd attachment ,which was undesirable
    I see. The docs say that fillPath() doesn't draw the outline, but I wonder whether this is really true. Does this grey ellipse change when you change the pen?

  5. #5
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problem with painter's fillpath() method

    ya ,you are right the fillpath() doesnt draws the outline ,the grey circle suronding my green circle was due to the pen the reason for it was that my pen wasnt deactivated ,so in any subsequent drawing method it first uses draws through the pen and then fill's the path...i mean to say if u dont deactivate the pen then fillpath not only fills the path but it draws the path also ..i hope its helpful.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some problem with painter's fillpath() method

    Quote Originally Posted by salmanmanekia View Post
    ya ,you are right the fillpath() doesnt draws the outline ,the grey circle suronding my green circle was due to the pen the reason for it was that my pen wasnt deactivated
    Wait, if that grey ellipse was caused by the pen settings, then fillPath() does draw the outline. Which Qt version do you use?

  7. #7
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problem with painter's fillpath() method

    what i understood is that fillpath() depends on pen ...i mean to say that if pen is not deactivated then fillpath not only fills the path but also draws it and if you deactivate a pen then the fillpath only fills the path....i hope you understand what i am trying to say.....any ways i am using qt 4.4

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some problem with painter's fillpath() method

    Quote Originally Posted by salmanmanekia View Post
    what i understood is that fillpath() depends on pen ...i mean to say that if pen is not deactivated then fillpath not only fills the path but also draws it and if you deactivate a pen then the fillpath only fills the path....
    Yes, but that's what drawPath() is supposed to do. According to the docs fillPath() should disregard the pen.

    Quote Originally Posted by salmanmanekia View Post
    i am using qt 4.4
    I smell a bug here.

  9. #9
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problem with painter's fillpath() method

    but that's what drawPath() is supposed to do
    yes you are right fillPath() only fills the path and drawpath() only draws it...

    According to the docs fillPath() should disregard the pen.
    in my case it isnt disregarding the pen,i mean it is considering it...

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.