[Qt] Проблема с заливкой QPainter
Код:
void Paint::paintEvent(QPaintEvent *)
{
path.moveTo(100,60);
QPolygonF polygon;
polygon << QPointF(100,60) << QPointF(100,160) << QPointF(20,160) \
<< QPointF(20,220) << QPointF(70,220) << QPointF(70,400);
path.addPolygon(polygon);
path.lineTo(100,60);
path.lineTo(100,160);
path.lineTo(20,160);
path.lineTo(20,220);
path.lineTo(70,220);
path.lineTo(70,400);
QRect rect1(45,400,50,50);
path.arcTo(rect1,90,180);
QRect rect2(70,425,50,50);
path.moveTo(120,450);
path.arcTo(rect2,0,180);
path.moveTo(120,450);
path.lineTo(170,450);
QRect rect3(170,425,50,50);
path.moveTo(220,450);
path.arcTo(rect3,0,180);
path.moveTo(220,450);
path.lineTo(270,450);
QRect rect4(270,425,50,50);
path.moveTo(320,450);
path.arcTo(rect4,0,180);
path.moveTo(320,450);
path.lineTo(320,400);
QRect rect5(295,350,50,50);
path.arcTo(rect5,270,180);
QRect rect6(320,325,50,50);
path.moveTo(370,350);
path.arcTo(rect6,0,180);
path.moveTo(370,350);
path.lineTo(370,300);
path.lineTo(440, 300);
path.lineTo(440,160);
QRect rect7(415,110,50,50);
path.arcTo(rect7,270,180);
path.lineTo(370,110);
QRect rect8(270,60,100,100);
path.moveTo(270,110);
path.arcTo(rect8,180,180);
path.moveTo(270,110);
path.lineTo(270,10);
path.lineTo(250,10);
path.lineTo(250,60);
path.lineTo(200,60);
QRect rect9(100,10,100,100);
path.moveTo(100,60);
path.arcTo(rect9,180,180);
QPainter img(this);
img.setRenderHint(QPainter::Antialiasing, true);
img.setPen(QPen(Qt::black, 4, Qt::SolidLine));
img.setBrush(QBrush(Qt::red, Qt::SolidPattern));
img.drawPath(path);
}
{
path.moveTo(100,60);
QPolygonF polygon;
polygon << QPointF(100,60) << QPointF(100,160) << QPointF(20,160) \
<< QPointF(20,220) << QPointF(70,220) << QPointF(70,400);
path.addPolygon(polygon);
path.lineTo(100,60);
path.lineTo(100,160);
path.lineTo(20,160);
path.lineTo(20,220);
path.lineTo(70,220);
path.lineTo(70,400);
QRect rect1(45,400,50,50);
path.arcTo(rect1,90,180);
QRect rect2(70,425,50,50);
path.moveTo(120,450);
path.arcTo(rect2,0,180);
path.moveTo(120,450);
path.lineTo(170,450);
QRect rect3(170,425,50,50);
path.moveTo(220,450);
path.arcTo(rect3,0,180);
path.moveTo(220,450);
path.lineTo(270,450);
QRect rect4(270,425,50,50);
path.moveTo(320,450);
path.arcTo(rect4,0,180);
path.moveTo(320,450);
path.lineTo(320,400);
QRect rect5(295,350,50,50);
path.arcTo(rect5,270,180);
QRect rect6(320,325,50,50);
path.moveTo(370,350);
path.arcTo(rect6,0,180);
path.moveTo(370,350);
path.lineTo(370,300);
path.lineTo(440, 300);
path.lineTo(440,160);
QRect rect7(415,110,50,50);
path.arcTo(rect7,270,180);
path.lineTo(370,110);
QRect rect8(270,60,100,100);
path.moveTo(270,110);
path.arcTo(rect8,180,180);
path.moveTo(270,110);
path.lineTo(270,10);
path.lineTo(250,10);
path.lineTo(250,60);
path.lineTo(200,60);
QRect rect9(100,10,100,100);
path.moveTo(100,60);
path.arcTo(rect9,180,180);
QPainter img(this);
img.setRenderHint(QPainter::Antialiasing, true);
img.setPen(QPen(Qt::black, 4, Qt::SolidLine));
img.setBrush(QBrush(Qt::red, Qt::SolidPattern));
img.drawPath(path);
}