Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_dialogs_qfontdialog.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 <QFont>
5#include <QWidget>
6#include <QFontDialog>
7
8class MyWidget : public QWidget
9{
11public:
13};
14
15void MyWidget::FontDialogExample(QWidget &myWidget)
16{
17 {
18 //! [0]
19 bool ok;
20 QFont font = QFontDialog::getFont(
21 &ok, QFont("Helvetica [Cronyx]", 10), this);
22 if (ok) {
23 // the user clicked OK and font is set to the font the user selected
24 } else {
25 // the user canceled the dialog; font is set to the initial
26 // value, in this case Helvetica [Cronyx], 10
27 }
28 //! [0]
29 }
30
31 {
32 //! [1]
33 myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));
34 //! [1]
35 }
36
37 {
38 //! [2]
39 bool ok;
40 QFont font = QFontDialog::getFont(&ok, QFont("Times", 12), this);
41 if (ok) {
42 // font is set to the font the user selected
43 } else {
44 // the user canceled the dialog; font is set to the initial
45 // value, in this case Times, 12.
46 }
47 //! [2]
48 }
49
50 {
51 //! [3]
52 myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));
53 //! [3]
54 }
55
56 {
57 //! [4]
58 bool ok;
59 QFont font = QFontDialog::getFont(&ok, this);
60 if (ok) {
61 // font is set to the font the user selected
62 } else {
63 // the user canceled the dialog; font is set to the default
64 // application font, QApplication::font()
65 }
66 //! [4]
67 }
68}