View Full Version : Qt drawing a filled rounded rectangle with border

22nd March 2015, 15:16
I want to draw a rectangle with rounded corners (border radius same for all 4 corners) with a specific color filing the entire rectangle, and a separate border color (say border is 1 px wide).

From my observation, Qt provides three methods - fillRect and drawRect and drawRoundedRect. There is, however, no method like fillRoundedRect. Which means that I can draw a rounded rectangle but it won't be filled with the color I want.

How do I do it? And also, I read that due to some aliasing problems, the corners are often rendered equal. How do I set it as equal for all four? Will painter.setRenderHint(QPainter::Antialiasing) suffice? Or do I have to do anything else?

23rd March 2015, 08:54
The fillXYZ methods are just for convenience, to require less calls for the most common area types that need filling.

You can fill any area type by setting a brush on the painter before calling the respective draw function.

The pen decides the color of the border, the brush for the filling.