Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qfontdatabase_snippets.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtWidgets>
5
7void wrapper()
8{
10QTreeWidget fontTree;
11fontTree.setColumnCount(2);
12fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes");
13
14const QStringList fontFamilies = QFontDatabase::families();
15for (const QString &family : fontFamilies) {
16 QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree);
17 familyItem->setText(0, family);
18
19 const QStringList fontStyles = QFontDatabase::styles(family);
20 for (const QString &style : fontStyles) {
21 QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
22 styleItem->setText(0, style);
23
25 const QList<int> smoothSizes = QFontDatabase::smoothSizes(family, style);
26 for (const auto &points : smoothSizes)
28
29 styleItem->setText(1, sizes.trimmed());
30 }
31}
33} // wrapper
34} // qfontdatabase_snippets
static QStringList families(WritingSystem writingSystem=Any)
Returns a sorted list of the available font families which support the writingSystem.
static QList< int > smoothSizes(const QString &family, const QString &style)
Returns the point sizes of a font that has family family and style styleName that will look attractiv...
static QStringList styles(const QString &family)
Returns a list of the styles available for the font family family.
Definition qlist.h:74
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:7822
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class.
Definition qtreewidget.h:23
void setText(int column, const QString &text)
Sets the text to be displayed in the given column to the given text.
The QTreeWidget class provides a tree view that uses a predefined tree model.
void setColumnCount(int columns)
void setHeaderLabels(const QStringList &labels)
Adds a column in the header for each item in the labels list, and sets the label for each column.
GLfixed GLfixed GLint GLint GLfixed points
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes