[Interest] Text rendering problem.

william.crocker at analog.com william.crocker at analog.com
Sat Jul 18 21:26:53 CEST 2015


On 07/18/2015 06:34 AM, Elvis Stansvik wrote:
> 2015-07-18 1:13 GMT+02:00 Bill Crocker<william.crocker at analog.com>:
>>
>> Hello:
>>
>> I am having a text rendering problem.
>>
>
>> 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);
>

Elvis:

You are the mam. That fixed it.

I forgot the most import rule of software engineering in the 21st century:

"No matter how obscure the problem, you are not the first to encounter it.
  Others have come before you, solved the problem and those solutions are
  there for all to see if you Google the right subject."

Bill

>> 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 at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list