Unsolved How to display path with QRegion member of Ellipse type correctly?
-
Hello everyone! I have few questions about QPainter, QRegion and Clipping.
My goal is to dislay intersection of two ellipses. Fitst, QPainter draws ellipses correctly:
void Field1::paintEvent(QPaintEvent *event) {
QPainter pntr;
QRect r1(50, 50, 100, 100);
QRect r2(100, 50, 100, 100);
pntr.begin(this);
pntr.setBrush(Qt::yellow);
pntr.drawEllipse(r1);
pntr.drawEllipse(r2);
pntr.end();
}
Next I try to create two regions reg1, reg2 of type ellipse and to get region reg3 that is an intersection of reg1 and reg2. After that I add reg3 to QPainterPath p and draw it. The result contains an intersection with right shape but whith stripes of two colors yellow (brush color) and black. Why it isn't full yellow and contains those stripes?
void Field1::paintEvent(QPaintEvent *event) {
QPainter pntr;
QRect r1(50, 50, 100, 100);
QRect r2(100, 50, 100, 100);
pntr.begin(this);
pntr.setBrush(Qt::yellow);
QRegion reg1(r1, QRegion::Ellipse);
QRegion reg2(r2, QRegion::Ellipse);
QRegion reg3 = reg1.intersected(reg2);
QPainterPath p;
p.addRegion(reg3);
pntr.drawPath(p);
pntr.end();
}
What is wrong? If I try to get intersection of rectangles everything is ok:
QRegion reg1(r1, QRegion::Rectangle);
QRegion reg2(r2, QRegion::Rectangle);
Also I tried to use clipping, specifically functions setClipRegion and setClipPath with function update() and it has no effect, nothing is displayed
pntr.setClipping(true);
pntr.setClipPath(p);
this->update();
or
pntr.setClipping(true);
pntr.setClipRegion(reg3);
this->update();It seems, that is not enough. But I didn't find in documentation more actions to do. How it should be? And the last question, expression pntr.setRenderHint(QPainter::Antialiasing, true); doesn't help to make the contour of shape smooth, it has no effect. What is wrong with it? Thanks.
P.S. If i use setClipPath() or setClipRegion() and after that draw one of start rectangulars, result looks like the right one, but whatever it contains some black pixels at the right side. Is it normal? What is wrong??
void Field1::paintEvent(QPaintEvent *event) {
QPainter pntr;
QRect r1(50, 50, 100, 100);
QRect r2(100, 50, 100, 100);
pntr.begin(this);
pntr.setBrush(Qt::yellow);
pntr.setClipping(true);
QRegion reg1(r1, QRegion::Ellipse);
QRegion reg2(r2, QRegion::Ellipse);
QRegion reg3 = reg1.intersected(reg2);
QPainterPath p;
p.addRegion(reg3);
pntr.setClipRegion(reg3);
pntr.drawEllipse(r1);
pntr.end();
}
-
I understood what is wrong with path, intersected region consists of many rectangles, and they are circled with black pen. So to remove black stripes i added pntr.setPen(Qt::NoPen); and no more black lines. So variant with drawPath() works. Now, how to use setClipRegion() or setClipPath() with update()? It doesn't display anything.