PDA

View Full Version : Some problem with painter's fillpath() method



salmanmanekia
25th June 2008, 10:23
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


#include <QGraphicsItem>
#include <QPainter>
#include <QPainterPath>

class ConfirmationScene:public QGraphicsItem
{
public:
QRectF r1;

QPainterPath path;



void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
QRectF boundingRect() const;

ConfirmationScene();
~ConfirmationScene();
};


SOURCE FILE


#include "ConfirmationScene.h"

ConfirmationScene::ConfirmationScene()
{
r1.setRect(10,10,50,50);
path.addEllipse(r1);

}

void ConfirmationScene::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{

painter->setPen(QPen(QBrush(Qt::gray,Qt::SolidPattern),30,Q t::SolidLine,Qt::FlatCap,Qt::MiterJoin));
painter->drawEllipse(0, 0, 200, 200);

painter->fillPath(path,QBrush(Qt::green,Qt::SolidPattern));
painter->drawPath(path);
}
QRectF ConfirmationScene::boundingRect() const
{
qreal penWidth = 150;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,20 + penWidth / 2, 20 + penWidth / 2);
}
ConfirmationScene::~ConfirmationScene()
{
}

jacek
25th June 2008, 23:27
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?

salmanmanekia
26th June 2008, 07:46
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 :)

jacek
26th June 2008, 22:19
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?

salmanmanekia
27th June 2008, 07:58
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.

jacek
27th June 2008, 15:02
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?

salmanmanekia
29th June 2008, 12:46
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

jacek
29th June 2008, 15:56
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.


i am using qt 4.4
I smell a bug here. ;)

salmanmanekia
30th June 2008, 13:31
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...