Results 1 to 5 of 5

Thread: Draw multiple color line

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Draw multiple color line

    Hello all.,

    I got stuck somewhere in drawing a line with two colors.
    Well i want to draw horizontal, vertical, slant lines with two colors one is above the other just like a sandwich.
    eg.. "======================================" just like this. above line of different color and lower line of different color. but without any space in between both.

    i have tried

    Qt Code:
    1. QLinearGradient gradient1;
    2. gradient1.setColorAt(0.0, Qt::darkBlue);
    3. gradient1.setColorAt(0.1, Qt::red);
    4. painter.setPen(QPen(QBrush(gradient1), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    To copy to clipboard, switch view to plain text mode 

    but nothing works for me. it just draw line of color red ...

    Any idea how to make it possible?
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Draw multiple color line

    Draw two different lines with different colors
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Draw multiple color line

    so this means i have to calculate the initial position and ending position of other line with respect to the current line.?
    is there any painter property or something which can do this. even if i draw line or if i draw curve or any other shape.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Draw multiple color line

    so this means i have to calculate the initial position and ending position of other line with respect to the current line.?
    Yes, based on the pen width, and orientation.

    is there any painter property or something which can do this. even if i draw line or if i draw curve or any other shape.
    Have a look at QPainter::rotate(), it might be of help.

    Do want to draw these line on one widget, or each of these is an indipendent widget?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    karankumar1609 (19th August 2013)

  6. #5
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Draw multiple color line

    i just want to draw these lines on a single widget.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Similar Threads

  1. Draw line with inverted background color
    By viswanath in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2011, 03:57
  2. To draw a line
    By vinayaka in forum Qt Quick
    Replies: 1
    Last Post: 6th June 2011, 10:53
  3. Draw Line
    By sagirahmed in forum Newbie
    Replies: 5
    Last Post: 18th October 2010, 07:49
  4. Draw Line
    By aloysiusjegan in forum Qwt
    Replies: 4
    Last Post: 12th February 2009, 11:02
  5. Best way to draw a Line
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2008, 09:57

Tags for this Thread

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.