diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-08-13 14:17:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-08-14 14:39:20 +0200 |
commit | a0b021d1366c772cd9c2cefcb1c47b47c35b5517 (patch) | |
tree | f5d685be7eab2c68f66c9c943e93e62b39e04fda /examples | |
parent | b3431a9553ec11b85b5e91c67b1ebaa6e1bfd59b (diff) |
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 <shawn.rutledge@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/widgets/painting/fontsampler/mainwindow.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
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( |