From a0b021d1366c772cd9c2cefcb1c47b47c35b5517 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 13 Aug 2014 14:17:33 +0200 Subject: Fix selection of fonts based on styleName By carrying the styleName through from QFontDef to bestFoundry and giving it to bestStyle that can use it we can accurately match fonts based on styleName. This makes it possible to match styles such as DejaVu Sans Condensed and Ubuntu Medium. The example fontsampler is updated so it can actually sample all the different styles it lists. Change-Id: I381effc74130311f98794cd07d30be10dee4fe45 Reviewed-by: Shawn Rutledge --- examples/widgets/painting/fontsampler/mainwindow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'examples/widgets/painting/fontsampler/mainwindow.cpp') diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp index 516ba5e2bc..bb7b7c7c28 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.cpp +++ b/examples/widgets/painting/fontsampler/mainwindow.cpp @@ -143,7 +143,9 @@ void MainWindow::showFont(QTreeWidgetItem *item) QString oldText = textEdit->toPlainText().trimmed(); bool modified = textEdit->document()->isModified(); textEdit->clear(); - textEdit->document()->setDefaultFont(QFont(family, 32, weight, italic)); + QFont font(family, 32, weight, italic); + font.setStyleName(style); + textEdit->document()->setDefaultFont(font); QTextCursor cursor = textEdit->textCursor(); QTextBlockFormat blockFormat; @@ -324,6 +326,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) // Calculate the maximum width and total height of the text. foreach (int size, sampleSizes) { QFont font(family, size, weight, italic); + font.setStyleName(style); font = QFont(font, painter->device()); QFontMetricsF fontMetrics(font); QRectF rect = fontMetrics.boundingRect( @@ -357,6 +360,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer) // Draw each line of text. foreach (int size, sampleSizes) { QFont font(family, size, weight, italic); + font.setStyleName(style); font = QFont(font, painter->device()); QFontMetricsF fontMetrics(font); QRectF rect = fontMetrics.boundingRect(QString("%1 %2").arg( -- cgit v1.2.3