Results 1 to 2 of 2

Thread: QLinearGradient inconsistent behavior with QPainter::drawLine

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

    Question QLinearGradient inconsistent behavior with QPainter::drawLine

    After looking at this post, I did a small program to test the QLinearGradient, and it appears that that QLinearGradient does not affect the perfect horizontal and perfect vertical lines, that drawn using QPainter::drawLine(). Before I convince myself that this is a bug I wanted to check with the forum that did I miss anything?

    Here is an example, note the perfect horizontal and perfect vertical line are not affected by gradient. I have tested this on
    1. Qt 4.8.1, MinGw 4.6.2, Win 7 32 bit
    2. Qt 5.0.1, MinGw 4.7.0, Win 7 32 bit

    Here is the Qt 5.0.1 example
    QLinearGradient.jpg
    Qt Code:
    1. #include <QtGui>
    2. #include <QtWidgets>
    3. #include <QApplication>
    4.  
    5. class Widget : public QWidget
    6. {
    7. public:
    8. Widget(QWidget *parent = 0) : QWidget(parent) {}
    9.  
    10. protected:
    11. void paintEvent(QPaintEvent *)
    12. {
    13. v.setCoordinateMode(QGradient::ObjectBoundingMode);
    14.  
    15. h.setCoordinateMode(QGradient::ObjectBoundingMode);
    16.  
    17. QBrush vBrush(v);
    18. QBrush hBrush(h);
    19.  
    20. QPainter painter(this);
    21.  
    22. QPen p = painter.pen();
    23. p.setWidth(25);
    24.  
    25. p.setBrush(vBrush);
    26. painter.setPen(p);
    27. painter.drawLine(QPointF(100,100),QPointF( 99,200));
    28. painter.drawLine(QPointF(200,200),QPointF(200,100));
    29. painter.drawLine(QPointF(300,100),QPointF(301,200));
    30.  
    31. p.setBrush(hBrush);
    32. painter.setPen(p);
    33. painter.drawLine(QPointF(400,100),QPointF(500, 99));
    34. painter.drawLine(QPointF(400,200),QPointF(500,200));
    35. painter.drawLine(QPointF(400,300),QPointF(500,301));
    36. }
    37. };
    38.  
    39. int main(int argc, char *argv[])
    40. {
    41. QApplication a(argc, argv);
    42.  
    43. Widget * widget = new Widget;
    44. widget->setWindowTitle("QLinearGradient");
    45. widget->showMaximized();
    46.  
    47. return a.exec();
    48. }
    To copy to clipboard, switch view to plain text mode 
    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.

  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: QLinearGradient inconsistent behavior with QPainter::drawLine

    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.

Similar Threads

  1. QPainter::drawLine(): straight lines look aliased
    By xqrp in forum Qt Programming
    Replies: 4
    Last Post: 19th January 2012, 13:18
  2. Replies: 1
    Last Post: 29th June 2011, 16:52
  3. Apparently inconsistent compiler behavior
    By Computer Hater in forum Newbie
    Replies: 6
    Last Post: 28th November 2010, 20:35
  4. QT inconsistent performance !!!
    By gontham in forum Qt Programming
    Replies: 7
    Last Post: 12th November 2010, 23:51
  5. Inconsistent behaviour of QVBoxLayout
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2008, 18:36

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.