How to erase the intersecting part of the two rectangles in Qt? -
i developing speech bubble project. using frameless qdialog
wherein painted 2 elliptical rectangles in intersecting way shown below.
how remove intersecting part here? have marked part in image.
i new qt. code is:
qpainter painter(this); painter.save(); painter.setrenderhint(qpainter::antialiasing); qpen pen(qcolor(65, 167, 243), 3,qt::solidline); qbrush brush(qcolor(255, 255, 255,204)); painter.setpen(pen); painter.setbrush(brush); qpainterpath rounded_rect; rounded_rect.addroundedrect(qrectf(20, 0, 180, 100), 16, 16); rounded_rect.addroundedrect(qrectf(0, 50 - 20, 40, 40 ), 16, 16); painter.setclippath(rounded_rect); qregion maskregion = painter.clipregion(); setmask(maskregion); painter.drawpath(rounded_rect); painter.restore();
it possible. should take @ qt documentation:
- qwidget::setmask()
- qregion
- shape clock example demonstration
edit: should change code following (not tested!)
qpainterpath p1, p2; p1.addroundedrect(qrectf(20, 0, 180, 100), 16, 16); p2.addroundedrect(qrectf(0, 50 - 20, 40, 40 ), 16, 16); p1 += p2; // or -= if want remove part qregion r(p1.tofillpolygon().topolygon()); setmask(r);
edit 2: solution overwrite paintevent()
instead of creating mask, 1 paint on transparent window overwriting paintevent
, painting background of arbitrary complex form. i'm not sure if working qdialog based windows.
Comments
Post a Comment