这是TestCode:
#include <QApplication>
#include <QGraphicsRectItem>
#include <QGraphicsView>
#include <QLinearGradient>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView *w = new QGraphicsView();
w->showMaximized();
w->setScene(new QGraphicsScene());
w->setSceneRect(0,0,w->width(),w->height());
QPointF p1(0,0);
QPointF p2(580,80);
QPointF p3(0,40);
QPointF p4(580,40);
QColor c1("#aa55ff");
QColor c2("#aaffff");
QLinearGradient g1(p1,p2);
g1.setColorAt(0,c1);
g1.setColorAt(1,c2);
QLinearGradient g2(p3,p4);
g2.setColorAt(0,c1);
g2.setColorAt(1,c2);
QGraphicsRectItem *r1 = w->scene()->addRect(0,0,580,80,QPen(),QBrush(g1));
QGraphicsRectItem *r2 = w->scene()->addRect(0,0,580,80,QPen(),QBrush(g2));
r2->setPos(0,90);
return a.exec();
}
事物是g1应该是对角线的渐变,而g2应该是水平渐变。
但是当跑步时,两人最终看起来都是水平的(比如g2应该看起来)。但是g1应该是对角线的。我做错了什么,我该如何解决?