0

Im using following code for making the edges of rectangle round... but getting the top left and right different from the bottom left and right.

How can I fix this?

   QRegion ErrorCallout::roundRect(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;
}

this->roundRect(rect,5);

Like below: enter image description here

Ankul
  • 53
  • 9
  • Did you try this way? http://www.qtcentre.org/threads/49787-QGraphicsRectItem-rounded-corners – ni1ight May 26 '17 at 08:51
  • Also what happens when you change the "r" ? – ni1ight May 26 '17 at 09:14
  • It depends upon the value of r. If it increases it keeps on increasing the radius of ellipse in the same ratio(uneven edges). and If I decrease r value it becomes rectangle with sharp edges. – Ankul May 26 '17 at 11:09
  • @ni1ight: I have tried this... I need the rectangle instead of directly painting it. – Ankul May 26 '17 at 11:10
  • What are you trying to do? What do you need the region for? You can draw transparent widgets, including transparent top-level widgets, without using any regions. Regions define a shape without any alpha blending and look awful and perform poorly when used as masks. Instead of using a region, just draw what you want and leave the rest of the widget transparent. – Kuba hasn't forgotten Monica May 26 '17 at 12:23

0 Answers0