PDA

View Full Version : How to draw a filled round rect?



high_flyer
10th May 2006, 23:08
Hi,

As the subject says.
I can find the normal fillRect() function, but not for a round rect...
But the docs say:

void QPainter::drawRoundRect ( const QRectF & r, int xRnd = 25, int yRnd = 25 )

Draws a rectangle r with rounded corners.

The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.

Help?

wysota
10th May 2006, 23:29
Did you set a brush (QBrush) for your painter?

high_flyer
10th May 2006, 23:34
Thanks, so it fills automatically when there is a brush deifned, which means I need to excplicitly set brush "on" and "off" if I want just the outline or filled round rect...
Why is it done like that for round rect, and for normal rect they offered a fillRect() methods?
Hmm...

wysota
10th May 2006, 23:37
Because fillRect is not for drawing rectangles. You should use QPainter::drawRect() for that. QPainter::fillRect() is for filling areas (and by the way, it takes a QBrush as its argument).

high_flyer
10th May 2006, 23:44
I know, fill rect FILLS rectangles.
Which means you have a method for drawing rects and a method for filling them.
But not so for round rects, where you only have one method for drawing which also fills it if the brush is set.
A drawRect will not fill a rect even if brush is set.

wysota
11th May 2006, 00:05
I know, fill rect FILLS rectangles.
It is used for filling areas in general.


But not so for round rects, where you only have one method for drawing which also fills it if the brush is set.
Like for all other shapes.


A drawRect will not fill a rect even if brush is set.

Are you sure? Try running the code from attachment.

high_flyer
11th May 2006, 09:37
It is used for filling areas in general.
I am not sure what do you mean by that...
Filling areas that are not rectangles as well?
How so?

wysota
11th May 2006, 10:23
Because there are methods for filling paths. I think these are only convienience methods. There are probably implemented using drawRect and drawPath with null pens. You can check that yourself in the source code. In short, the difference between drawRect and fillRect is that the latter doesn't use the pen.

high_flyer
11th May 2006, 10:26
Thanks!

(this text is only in order to allow me to post a one word post ;) )