Draw a rectangle alternating two colors with qPainter
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.
Re: Draw a rectangle alternating two colors with qPainter
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.
Re: Draw a rectangle alternating two colors with qPainter
Thanks, it's a solution but it's not what I'm looking for. Any other suggestion?
Re: Draw a rectangle alternating two colors with qPainter
Did you try this?
Code:
_painter.setPen( Qt::DashLine );
Re: Draw a rectangle alternating two colors with qPainter
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.
Re: Draw a rectangle alternating two colors with qPainter
Quote:
Originally Posted by jacek
Did you try this?
Code:
_painter.setPen( Qt::DashLine );
It will only change the outline, and he wants the filling striped. At least that's what I understand...
Re: Draw a rectangle alternating two colors with qPainter
Quote:
It will only change the outline, and he wants the filling striped. At least that's what I understand...
Exactly jacek.
Quote:
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...
Re: Draw a rectangle alternating two colors with qPainter
Then we must have misunderstood what you are looking for :confused:
Re: Draw a rectangle alternating two colors with qPainter
Could you provide a picture of what you want to achieve?
1 Attachment(s)
Re: Draw a rectangle alternating two colors with qPainter
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.
Re: Draw a rectangle alternating two colors with qPainter
Quote:
Originally Posted by SkripT
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.
Re: Draw a rectangle alternating two colors with qPainter
Have you seen QRubberBand?
Re: Draw a rectangle alternating two colors with qPainter
Quote:
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