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

Text bounding rectangles are incorrectly reported on OS/X

    XMLWordPrintable

Details

    • macOS

    Description

      Qt reports incorrect bounding rectangles for drawn text under OS/X (Tested with Snow Leopard).
      The sample below executes correctly on Windows, where the red rectangle encloses the text.
      On OS/X, portions of the text are visible outside the reported bounding rectangle.
      This issue occurs both with setPixelSize() and setPointSize(), and with both QFontMetrics and QPainter boundingRect().

      #include <QtGui/QApplication>
      #include <QMainWindow>
      #include <QPainter>
      #include <QLabel>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QMainWindow *mainWindow = new QMainWindow();
      QLabel *label = new QLabel( mainWindow );

      QImage image(200,200,QImage::Format_ARGB32_Premultiplied);
      QFont font("Arial");
      QPainter painter;
      QRect outrect;

      if( painter.begin( &image ) )

      { painter.fillRect( image.rect(), Qt::white ); font.setPixelSize(10); painter.setFont( font ); painter.setPen( Qt::black ); painter.drawText( 10,10, image.width()-20,image.height()-20, Qt::AlignTop|Qt::AlignLeft|Qt::TextSingleLine, "Testing", &outrect ); painter.setPen( Qt::red ); painter.drawRect( outrect ); font.setPixelSize(20); painter.setFont( font ); painter.setPen( Qt::black ); painter.drawText( 10,30, image.width()-20,image.height()-20, Qt::AlignTop|Qt::AlignLeft|Qt::TextSingleLine, "Testing", &outrect ); painter.setPen( Qt::red ); painter.drawRect( outrect ); font.setPixelSize(30); painter.setFont( font ); painter.setPen( Qt::black ); painter.drawText( 10,60, image.width()-20,image.height()-20, Qt::AlignTop|Qt::AlignLeft|Qt::TextSingleLine, "Testing", &outrect ); painter.setPen( Qt::red ); painter.drawRect( outrect ); painter.end(); }

      label->setPixmap( QPixmap::fromImage(image) );
      label->setGeometry( 10,10, image.width(), image.height() );
      mainWindow->resize( 220, 220 );
      mainWindow->show();

      return a.exec();
      }

      Attachments

        1. screenshot-1.jpg
          screenshot-1.jpg
          10 kB
        2. image.png
          image.png
          5 kB
        3. main.cpp
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            sirreal Johan Lindh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes