Angelo Moriconi
8th January 2008, 16:22
Hi All !
I would like to create some vector graphics ballons that can be customized by the user (changing the scale factors and position of the stem.
Internally I use QPainter to draw all the balloons stuff including the balloons shapes.
For every type of balloon I create, on the fly, a QPainterPath from an union of several polygons.
I try to do something like this with a strange results that probably depends from the painterpath position:
http://img262.imageshack.us/img262/6376/balloonws1.th.png (http://img262.imageshack.us/my.php?image=balloonws1.png)
The code (very straightfoward and not optimize) is the following:
QPolygonF Balloon::getSoftPolygon()
{
int w = m_rect.width();
int h = m_rect.height();
QPoint center = m_rect.center()-QPoint(w*0.25,h*0.25);
QRect smallRect(center.x(),center.y(),w*0.5,h*0.5);
QPainterPath s2;
s2.addEllipse(smallRect.translated(w*0.2,0));
QPainterPath s3;
s3.addEllipse(smallRect.translated(-w*0.2,0));
QPainterPath s4;
s4.addEllipse(smallRect.translated(w*0.1,-h*0.2));
QPainterPath s5;
s5.addEllipse(smallRect.translated(-w*0.1,-h*0.2));
QPainterPath s6;
s6.addEllipse(smallRect.translated(w*0.1,h*0.2));
QPainterPath s7;
s7.addEllipse(smallRect.translated(-w*0.1,h*0.2));
QPolygonF p = s2.united(s3).united(s4).united(s5).united(s6).uni ted(s7).toFillPolygon();
return p;
}
Then in the paintEvent...
QPolygonF stemPolygon = getStemPolygon();
QPainterPath overallShape = QPainterPath();
overallShape.addPolygon(getSoftPolygon().united(st emPolygon));
Probably exist a more simple way to create a "soft" balloon using QPainterPath.
Any suggestions and different solution are welcome !!
Bye, bye !
I would like to create some vector graphics ballons that can be customized by the user (changing the scale factors and position of the stem.
Internally I use QPainter to draw all the balloons stuff including the balloons shapes.
For every type of balloon I create, on the fly, a QPainterPath from an union of several polygons.
I try to do something like this with a strange results that probably depends from the painterpath position:
http://img262.imageshack.us/img262/6376/balloonws1.th.png (http://img262.imageshack.us/my.php?image=balloonws1.png)
The code (very straightfoward and not optimize) is the following:
QPolygonF Balloon::getSoftPolygon()
{
int w = m_rect.width();
int h = m_rect.height();
QPoint center = m_rect.center()-QPoint(w*0.25,h*0.25);
QRect smallRect(center.x(),center.y(),w*0.5,h*0.5);
QPainterPath s2;
s2.addEllipse(smallRect.translated(w*0.2,0));
QPainterPath s3;
s3.addEllipse(smallRect.translated(-w*0.2,0));
QPainterPath s4;
s4.addEllipse(smallRect.translated(w*0.1,-h*0.2));
QPainterPath s5;
s5.addEllipse(smallRect.translated(-w*0.1,-h*0.2));
QPainterPath s6;
s6.addEllipse(smallRect.translated(w*0.1,h*0.2));
QPainterPath s7;
s7.addEllipse(smallRect.translated(-w*0.1,h*0.2));
QPolygonF p = s2.united(s3).united(s4).united(s5).united(s6).uni ted(s7).toFillPolygon();
return p;
}
Then in the paintEvent...
QPolygonF stemPolygon = getStemPolygon();
QPainterPath overallShape = QPainterPath();
overallShape.addPolygon(getSoftPolygon().united(st emPolygon));
Probably exist a more simple way to create a "soft" balloon using QPainterPath.
Any suggestions and different solution are welcome !!
Bye, bye !