title: painting QLinearGradient in QGraphicsScene
body: <p>I originally implement my graph by drawing all the content in the <code>QWidget::paintEvent()</code>. I have a function <code>drawHeatMapLegend()</code> to draw a box with QLinearGradient to represent a heat-map for my graph as legend.</p>
  
  <p><b>Original implementation</b></p>
  
  <pre><code>widMapGraph::widMapGraph(QWidget parent = 0) : QWidget(parent) {
      gradient_.setCoordinateMode(QGradient::ObjectBoundingMode);
      gradient_.setColorAt(0.0, Qt::green);
      gradient_.setColorAt(0.3, Qt::yellow);
      gradient_.setColorAt(0.6, Qt::red);
  }
  
  void widMapGraph::paintEvent(QPaintEvent *event) {
      QPainter painter(this);
      drawHeatMapLegend(&amp;painter);
  }
  
  void widMapGraph::drawHeatMapLegend(QPainter* painter) {
      QRect legendBox(30, 70, 25, 100);
      int left = legendBox.left() + legendBox.width() + 10;
      painter-&gt;save();
      painter-&gt;setPen(QPen());
      painter-&gt;setBrush(gradient_);
      painter-&gt;drawRect(legendBox);
      painter-&gt;drawText(left, legendBox.top(), "0.00%");
      painter-&gt;drawText(left, legendBox.top() + legendBox.height() / 2, "50.00%");
      painter-&gt;drawText(left, legendBox.top() + legendBox.height(), "100.00%");
      painter-&gt;restore();
  } // end: (widMapGraph::drawHeatMapLegend)
  </code></pre>
  
  <p>Now, I try to use QGraphicScene/QGraphicsView framework for my graph and I implement a subclass of QGraphicsRectItem for my map legend.</p>
  
  <p><b>Class definition</b></p>
  
  <pre><code>class MapLegend : public QObject, public QGraphicsRectItem {
      Q_OBJECT
  public:
      MapLegend(QGraphicsItem *parent = 0);
      void paint (QPainter *painter,
                  const QStyleOptionGraphicsItem *option,
                  QWidget *widget);
      QLinearGradient gradient_;
      /* other members */
  }
  </code></pre>
  
  <p><b>Class implementation</b></p>
  
  <pre><code>MapLegend::MapLegend(QGraphicsItem *parent) : QGraphicsRectItem(parent) {
      setRect(30, 70, 25, 100);
      gradient_.setCoordinateMode(QGradient::ObjectBoundingMode);
      gradient_.setColorAt(0.0, Qt::green);
      gradient_.setColorAt(0.3, Qt::yellow);
      gradient_.setColorAt(0.6, Qt::red);
  } // end_ctor(MapLegend)
  
  void MapLegend::paint(QPainter *painter,
                        const QStyleOptionGraphicsItem *option,
                        QWidget *widget)
  {
      Q_UNUSED(option);
      Q_UNUSED(widget);
      int left = rect().left() + rect().width() + 10;
      painter-&gt;setPen(QPen());
      painter-&gt;setBrush(gradient_);
      painter-&gt;drawRect(rect());
      painter-&gt;drawText(left, rect().top(), "0.00%");
      painter-&gt;drawText(left, rect().top() + rect().height() / 2, "50.00%");
      painter-&gt;drawText(left, rect().top() + rect().height(), "100.00%");
  } // end: MapLegend::paint()
  
  void My2ndGraph::task() {
      myView-&gt;scene()-&gt;clear();
      myView-&gt;scene()-&gt;addItem(myLegend); // myLegend is a class variable as MapLegend
      update();
  }
  </code></pre>
  
  <p><i>Result</i> The orange box shows two examples using 2nd implementation</p>
  
  <p><img src="https://i.stack.imgur.com/4KDJa.png" alt="Result"></p>
  
  <p><b>Question</b> The original implementation correctly show a gradient 'vertically' along the box, but the new implementation draw the gradient diagonally. Is there anything I missed that why the two implementations behavior dis-agree? Thanks</p>