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

Broken text when painted with a low point size and then scaled up in e.g. a graphics view

    XMLWordPrintable

Details

    Description

      Consider the following QGraphicsItem:

      QRectF MyGraphicsItem::boundingRect() const
      {
      return QRectF(-0.5, -0.5, 1.0, 1.0);
      }

      void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
      {
      QFont font = painter->font();
      font.setPointSizeF(0.05);
      painter->setFont(font);

      painter->drawText(boundingRect(), Qt::AlignCenter, tr("text"));
      }

      then:

      QGraphicsScene scene;
      scene.addItem(new MyGraphicsItem);

      QGraphicsView view(&scene);
      view.scale(200.0, 200.0);

      It seems natural to assume that this will work, since it will work with all other graphics view primitives, and since it's the final coordinate system of the view which should determine the results, not the initial coordinate system of the item. However, the text will not show at all in the case. If you draw the text to a point rather than a into a rect, it will be painted much too large, and lowering the point size will not alter the size of the text. Also, the letters will be painted on top of each other.

      If you change the coordinate system of the graphics item so that the point size is within a normal range, and then change the scale of the view accordingly, the example should work.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            esabraha Eskil Abrahamsen Blomfeldt
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes