Hi,
I have a QWidget (frameless) as my mainwindow. I want it to have rounded corners. Is there a way other than setMask() to make the corners rounded ?
Thanks.
Hi,
I have a QWidget (frameless) as my mainwindow. I want it to have rounded corners. Is there a way other than setMask() to make the corners rounded ?
Thanks.
Mithin
www.mithin.in
What make you think that setMask() is bad way ?
a life without programming is like an empty bottle
I did not say it is a bad way, I was just hoping that there might be a better and simpler way to do this.
Assuming that I use the setMask way, can you please give me a sample where i don't have to use an external image in order to set the mask.
Thanks a lot.
Mithin
www.mithin.in
Notice that QWidget has 2 overloads of setMask(). One takes QBitmap and another takes QRegion. A QRegion's RegionType can be ellipse. A large enough ellipse clips corners of a rectangle and gives a rounded rectangle..Originally Posted by munna
J-P Nurmi
Thanks for replying
I see your point but the problem is that I am having a square widget. This will always give a circular widget and not rounded corners.A QRegion's RegionType can be ellipse. A large enough ellipse clips corners of a rectangle and gives a rounded rectangle
Is it possible to subtract four small circles from the rectangle of the widget and then set the mask ?
Mithin
www.mithin.in
QRegion::subtract()Originally Posted by munna
You cannot substract the circles, you will end up having holes in the corners.Originally Posted by munna
This should help unless you already solved the prob
Qt Code:
{ QRegion region; // middle and borders region += rect.adjusted(r, 0, -r, 0); region += rect.adjusted(0, r, 0, -r); // top left // top right corner.moveTopRight(rect.topRight()); // bottom left corner.moveBottomLeft(rect.bottomLeft()); // bottom right corner.moveBottomRight(rect.bottomRight()); return region; } someWidget->setMask(roundedRect(someWidget->rect(), 20));To copy to clipboard, switch view to plain text mode
J-P Nurmi
nshenoy (4th July 2011), sabeesh (13th November 2007), Wojtek1990 (14th August 2010)
Or yet better, I think:
Qt Code:
{ painter.fillRect(pixmap.rect(), Qt::white); painter.setBrush(Qt::black); painter.drawRoundRect(pixmap.rect()); setMask(pixmap.createMaskFromColor(Qt::white)); }To copy to clipboard, switch view to plain text mode
J-P Nurmi
BatteryCell (22nd September 2007), JulesMC (17th June 2011), nitsandaniel (2nd May 2011), Wojtek1990 (14th August 2010)
Bookmarks