PDA

View Full Version : Draw a rectangle alternating two colors with qPainter



SkripT
23rd January 2006, 13:31
Hi all, I want to draw a rectangle with qPainter alternating the colors black & white: The rectangle has to looks like if it was made with dashed lines. I think that the solution could be setting the correct brush for the pen used to draw the rectangle, but I have tried different combinations with no success. Anybody knows how to do it?. Thanks.

wysota
23rd January 2006, 13:52
I think you could use gradients for that, but the result won't be perfect (it'll be a gradient and not striped box). Or you could draw many rectangles with different colours.

SkripT
23rd January 2006, 19:46
Thanks, it's a solution but it's not what I'm looking for. Any other suggestion?

jacek
23rd January 2006, 20:08
Did you try this?
_painter.setPen( Qt::DashLine );

yop
23rd January 2006, 20:09
...you could draw many rectangles with different colours.
I don't think that you'll find a better solution ;) You know you only have to create once, one black and one white rectangle and then just draw them one after the other repeatidly.

wysota
23rd January 2006, 20:33
Did you try this?
_painter.setPen( Qt::DashLine );

It will only change the outline, and he wants the filling striped. At least that's what I understand...

SkripT
24th January 2006, 09:51
It will only change the outline, and he wants the filling striped. At least that's what I understand...


Exactly jacek.




Quote:
Originally Posted by wysota
...you could draw many rectangles with different colours.
I don't think that you'll find a better solution You know you only have to create once, one black and one white rectangle and then just draw them one after the other repeatidly.

I think that the result doesn't looks like a stripped line...

yop
24th January 2006, 11:10
Then we must have misunderstood what you are looking for :confused:

wysota
24th January 2006, 11:21
Could you provide a picture of what you want to achieve?

SkripT
24th January 2006, 15:15
Very easy, what I want is simply a rubber band. The problem drawing it with setPen( Qt::DashLine ) is that you can only choose one colour, I want to choose the two colors: black & white.

jacek
24th January 2006, 15:21
The problem drawing it with setPen( Qt::DashLine ) is that you can only choose one colour, I want to choose the two colors: black & white.
You can draw white rectangle with a solid line and then a black one using dashed line.

wysota
24th January 2006, 15:24
Have you seen QRubberBand?

SkripT
25th January 2006, 00:12
You can draw white rectangle with a solid line and then a black one using dashed line.

One time more, thanks. I don't know what i was tinking of.... The solution is very easy :D