Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-1725

QGraphicsView draws 1pt text incorrectly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • Some future release
    • 4.3.3
    • GUI: Painting
    • None

    Description

      The following example shows that sometimes the position of text drawn is shifted by 1pixel:

      #include <QGraphicsView>
      #include <QGraphicsScene>
      #include <QGraphicsItem>
      #include <QTransForm>

      #include <QApplication>
      #include <iostream>

      class TextItem : public QGraphicsItem
      {
      public:
      TextItem(int y, int size)

      { text = "Only"; pointSize = 1; pt = QPointF(0,y); }

      QRectF boundingRect() const

      { QFont font(qApp->font()); font.setPointSizeF(pointSize); QFontMetrics fm(font); QRectF r = fm.boundingRect(text); r.moveTopLeft(QPointF(pt.x(),pt.y())); return r; }

      void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)

      { painter->setPen(Qt::red); QFont font(qApp->font()); font.setPointSizeF(pointSize); painter->setFont(font); painter->drawText(QPointF(pt.x(),pt.y()+pointSize), text); }

      QPointF pt;
      QString text;
      int pointSize;
      };

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

      QApplication app(argc,argv);

      QGraphicsView v;
      QGraphicsScene *scene = new QGraphicsScene();
      v.setScene(scene);

      QTransform t;
      t.scale(25.3,25.3);
      v.setTransform(t);

      int curY = 0;
      for (double i = 1; i < 50; i *= 1.05)

      { TextItem *item = new TextItem(curY,i); scene->addItem(item); curY += i; }

      v.setBackgroundBrush(Qt::black);
      v.show();
      return app.exec();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes