1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QFont>
#include <QWidget>
#include <QFontDialog>
class MyWidget : public QWidget
{
Q_OBJECT
public:
void FontDialogExample(QWidget &myWidget);
};
void MyWidget::FontDialogExample(QWidget &myWidget)
{
{
//! [0]
bool ok;
QFont font = QFontDialog::getFont(
&ok, QFont("Helvetica [Cronyx]", 10), this);
if (ok) {
// the user clicked OK and font is set to the font the user selected
} else {
// the user canceled the dialog; font is set to the initial
// value, in this case Helvetica [Cronyx], 10
}
//! [0]
}
{
//! [1]
myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));
//! [1]
}
{
//! [2]
bool ok;
QFont font = QFontDialog::getFont(&ok, QFont("Times", 12), this);
if (ok) {
// font is set to the font the user selected
} else {
// the user canceled the dialog; font is set to the initial
// value, in this case Times, 12.
}
//! [2]
}
{
//! [3]
myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));
//! [3]
}
{
//! [4]
bool ok;
QFont font = QFontDialog::getFont(&ok, this);
if (ok) {
// font is set to the font the user selected
} else {
// the user canceled the dialog; font is set to the default
// application font, QApplication::font()
}
//! [4]
}
}
|