static QRegion roundedRect
(const QRect
& rect,
int r
) {
// 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));
static QRegion roundedRect(const QRect& rect, int r)
{
QRegion region;
// middle and borders
region += rect.adjusted(r, 0, -r, 0);
region += rect.adjusted(0, r, 0, -r);
// top left
QRect corner(rect.topLeft(), QSize(r*2, r*2));
region += QRegion(corner, QRegion::Ellipse);
// top right
corner.moveTopRight(rect.topRight());
region += QRegion(corner, QRegion::Ellipse);
// bottom left
corner.moveBottomLeft(rect.bottomLeft());
region += QRegion(corner, QRegion::Ellipse);
// bottom right
corner.moveBottomRight(rect.bottomRight());
region += QRegion(corner, QRegion::Ellipse);
return region;
}
someWidget->setMask(roundedRect(someWidget->rect(), 20));
To copy to clipboard, switch view to plain text mode
Bookmarks