2015-07-18 1:13 GMT+02:00 Bill Crocker <william.croc...@analog.com>: > > 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?
>From some googling, I think it's because the hinting values are obtained when unscaled, and then used even when scaled. What you can do in your example is scene_font.setHintingPreference(QFont::PreferNoHinting); to prefer that hinting not be used at all. I tested this on X11/Linux. I'm attaching the before/after results. I'm not sure what effect this setting has on all the platforms, but it's just a hint so I guess it might be ignored on some of them. Cheers, Elvis > > > (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(); > } > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest