[Interest] Text rendering problem.

Bill Crocker william.crocker at analog.com
Sat Jul 18 01:13:14 CEST 2015


Hello:

I am having a text rendering problem.

The following code creates a QLabel and QGraphicsTextItem.
The QLabel text is 60 pt. The QGraphicsTextItem text size is 6 pt,
but then the view is scaled up by 10x. So, in the end both
pieces of text are the same size on the screen.

For me the QLabel text looks good while the
QGraphicsTextItem is very badly kerned (char spacing).

Does anyone know what is wrong
with the QGraphicsTextItem implementation?

(For all I know the QLabel text would be badly kerned
  at 6pt as well, but it is hard to see.)

Qt 4.8.6, RHEL 5.10

Thanks.

Bill

-------------------------
int
main( int argc, char **argv ) {
     QApplication app(argc,argv);

     int sz = 6, scale = 10;
     QString text = QString("Impedance");

     // Text size is 60.
     // This text renders well.
     QFont label_font = QFont("Arial",scale*sz,QFont::Bold);
     QLabel *label = new QLabel(text);
     label->setFont(label_font);

     // Text size is 6, then the view is zoomed in x10.
     // This text is not properly kerned.
     QFont scene_font = QFont("Arial",sz,QFont::Bold);
     QTextDocument *html = new QTextDocument;
     html->setDefaultFont(scene_font);
     html->setHtml(text);
     QGraphicsTextItem *gi = new QGraphicsTextItem;
     gi->setDocument(html);
     QGraphicsScene *sp = new QGraphicsScene;
     sp->addItem(gi);
     QGraphicsView *view = new QGraphicsView;
     view->setScene(sp);
     view->scale(scale,scale);

     QHBoxLayout *hbox = new QHBoxLayout;
     hbox->addWidget(label);
     hbox->addWidget(view);

     QWidget *wp = new QWidget;
     wp->setLayout(hbox);
     wp->show();

     app.exec();
}



More information about the Interest mailing list