Details
-
Bug
-
Resolution: Cannot Reproduce
-
P3: Somewhat important
-
4.6.3, 4.7.1
-
None
-
OS/X Snow Leopard, Qt 4.6.3
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();
}