Results 1 to 7 of 7

Thread: curve with QLinearGradient

  1. #1
    Join Date
    Jun 2016
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question curve with QLinearGradient

    Hello,

    I have a curve filled with a linear gradient which the colors depends on certain values.
    The problem is : if the curve have a concave shape or local minimum, there is a shift in the position of the colors at the same Y position of the minimum and after its X position, please see the image.
    Anyone could help me to find out why this happens

    cheers,


    helpme.jpg

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: curve with QLinearGradient

    Assuming, that you fill the curve using QwtPlotCurve::setBrush(), the problem should be somewhere in the paint engine of your system. What type of graphic system is your backend ?

    Uwe

  3. #3
    Join Date
    Jun 2016
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: curve with QLinearGradient

    Hi Uwe and thank you for your reply.

    Yes I used QwtPlotCurve::setBrush(). The problem persists on both OS ubuntu 16.04 and Windows 10.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: curve with QLinearGradient

    Then we are talking about the raster paint engine and you should be able to reproduce the problem with a small standalone application drawing a QPolygon to a QImage.

    Uwe

  5. #5
    Join Date
    Jun 2016
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: curve with QLinearGradient

    Indeed I was able to reproduce this in a simple polygon draw with qlineargradient :
    Qt Code:
    1. p.begin(this) ;
    2. QPolygon poly ;
    3. QLinearGradient g(0,0,500,0) ;
    4. g.setColorAt(0, Qt::red);
    5. g.setColorAt(0.2, Qt::yellow);
    6. g.setColorAt(0.4, Qt::green);
    7. g.setColorAt(0.401, Qt::yellow);
    8. g.setColorAt(0.6, Qt::cyan);
    9. g.setColorAt(0.602, Qt::black) ;
    10. g.setColorAt(0.8, Qt::blue);
    11. g.setColorAt(0.801, Qt::yellow);
    12. g.setColorAt(1, Qt::white);
    13. p.setBrush(g);
    14. poly << QPoint(0, 20) << QPoint(100, 300) << QPoint(200,20) << QPoint(300, 20) << QPoint(400, 20) << QPoint(500, 20) << QPoint(500,400) << QPoint(0, 400);
    15. p.drawPolygon(poly);
    16. p.end() ;
    To copy to clipboard, switch view to plain text mode 
    And this what it gave me test.png

    Does this mean that this is a bug in the raster paint engine ? could it be changed to other paint engine ?

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: curve with QLinearGradient

    Does this mean that this is a bug in the raster paint engine ?
    Yes.
    could it be changed to other paint engine ?
    First of all you could try a different version of Qt.

    With Qt4/X11 you could use the X11 paint engine, what is IMHO superior to all other options, when using Qwt: hardware accelerated + no bugs.
    There are also 2 different types of OpenGL paint engines. When using Qwt from SVN trunk you could play with the QwtPlotCanvas::OpenGLBuffer mode.

    But if I were in your shoes I would try:


    1. fill a temporary QImage with your gradient
    2. setting a clip path with the polygon
    3. draw the image


    Uwe

  7. The following user says thank you to Uwe for this useful post:

    yoshri92 (8th July 2016)

  8. #7
    Join Date
    Jun 2016
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Thumbs up Re: curve with QLinearGradient

    1. fill a temporary QImage with your gradient
    2. setting a clip path with the polygon
    3. draw the image

    That worked out.
    I overloaded the method QwtPlotCurve::fillCurve so it would do the same and it is acceptable.
    Thank you very much

Similar Threads

  1. Replies: 1
    Last Post: 29th September 2013, 09:12
  2. Stroke a curve with a QLinearGradient
    By alecail in forum General Programming
    Replies: 0
    Last Post: 13th March 2012, 00:03
  3. Replies: 4
    Last Post: 29th April 2010, 06:11
  4. Replies: 1
    Last Post: 22nd January 2010, 14:34
  5. Regarding qlineargradient
    By jjbabu in forum Qt Programming
    Replies: 6
    Last Post: 15th April 2009, 09:21

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.