Results 1 to 13 of 13

Thread: Draw a rectangle alternating two colors with qPainter

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question 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.
    Last edited by SkripT; 23rd January 2006 at 12:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a rectangle alternating two colors with qPainter

    Did you try this?
    Qt Code:
    1. _painter.setPen( Qt::DashLine );
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a rectangle alternating two colors with qPainter

    Quote Originally Posted by jacek
    Did you try this?
    Qt Code:
    1. _painter.setPen( Qt::DashLine );
    To copy to clipboard, switch view to plain text mode 
    It will only change the outline, and he wants the filling striped. At least that's what I understand...

  7. #7
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Draw a rectangle alternating two colors with qPainter

    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...
    Last edited by SkripT; 24th January 2006 at 08:59.

  8. #8
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw a rectangle alternating two colors with qPainter

    Then we must have misunderstood what you are looking for

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a rectangle alternating two colors with qPainter

    Could you provide a picture of what you want to achieve?

  10. #10
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:ashLine ) is that you can only choose one colour, I want to choose the two colors: black & white.
    Attached Images Attached Images

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Draw a rectangle alternating two colors with qPainter

    Have you seen QRubberBand?

  13. #13
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Draw a rectangle alternating two colors with qPainter

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.