PDA

View Full Version : QLinearGradient inconsistent behavior with QPainter::drawLine



Santosh Reddy
26th April 2013, 15:03
After looking at this post (http://www.qtcentre.org/threads/54256-Qpainter-draw-line), 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
8993


#include <QtGui>
#include <QtWidgets>
#include <QApplication>

class Widget : public QWidget
{
public:
Widget(QWidget *parent = 0) : QWidget(parent) {}

protected:
void paintEvent(QPaintEvent *)
{
QLinearGradient v = QLinearGradient(QPointF(0,0), QPointF(0,1));
v.setCoordinateMode(QGradient::ObjectBoundingMode) ;

QLinearGradient h = QLinearGradient(QPointF(0,0), QPointF(1,0));
h.setCoordinateMode(QGradient::ObjectBoundingMode) ;

QBrush vBrush(v);
QBrush hBrush(h);

QPainter painter(this);

QPen p = painter.pen();
p.setWidth(25);

p.setBrush(vBrush);
painter.setPen(p);
painter.drawLine(QPointF(100,100),QPointF( 99,200));
painter.drawLine(QPointF(200,200),QPointF(200,100) );
painter.drawLine(QPointF(300,100),QPointF(301,200) );

p.setBrush(hBrush);
painter.setPen(p);
painter.drawLine(QPointF(400,100),QPointF(500, 99));
painter.drawLine(QPointF(400,200),QPointF(500,200) );
painter.drawLine(QPointF(400,300),QPointF(500,301) );
}
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

Widget * widget = new Widget;
widget->setWindowTitle("QLinearGradient");
widget->showMaximized();

return a.exec();
}

Santosh Reddy
14th May 2013, 13:25
QTBUG-30959 (https://bugreports.qt-project.org/browse/QTBUG-30959)