blob: ab8521b465547afdb313896ba7c72b94185f0589 (
plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include <QStyleFactory>
#include <QWidget>
namespace src_gui_kernel_qapplication {
struct MyWidget
{
QSize sizeHint() const;
int foo = 0;
MyWidget operator- (MyWidget& other)
{
MyWidget tmp = other;
return tmp;
};
int manhattanLength() { return 0; }
};
//! [0]
QCoreApplication *createApplication(int &argc, char *argv[])
{
for (int i = 1; i < argc; ++i)
if (!qstrcmp(argv[i], "-no-gui"))
return new QCoreApplication(argc, argv);
return new QApplication(argc, argv);
}
int main(int argc, char *argv[])
{
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
if (qobject_cast<QApplication *>(app.data())) {
// start GUI version...
} else {
// start non-GUI version...
}
return app->exec();
}
//! [0]
void wrapper0() {
//! [1]
QApplication::setStyle(QStyleFactory::create("fusion"));
//! [1]
} // wrapper0
//! [3]
QSize MyWidget::sizeHint() const
{
return QSize(80, 25);
}
//! [3]
//! [4]
void showAllHiddenTopLevelWidgets()
{
const auto topLevelWidgets = QApplication::topLevelWidgets();
for (QWidget *widget : topLevelWidgets) {
if (widget->isHidden())
widget->show();
}
}
//! [4]
//! [5]
void updateAllWidgets()
{
const auto topLevelWidgets = QApplication::topLevelWidgets();
for (QWidget *widget : topLevelWidgets)
widget->update();
}
//! [5]
void startTheDrag() {};
void wrapper1() {
MyWidget startPos;
MyWidget currentPos;
int x = 0;
int y = 0;
//! [6]
if ((startPos - currentPos).manhattanLength() >=
QApplication::startDragDistance())
startTheDrag();
//! [6]
//! [7]
QWidget *widget = qApp->widgetAt(x, y);
if (widget)
widget = widget->window();
//! [7]
} // wrapper1
void wrapper2() {
QPoint point;
//! [8]
QWidget *widget = qApp->widgetAt(point);
if (widget)
widget = widget->window();
//! [8]
} // wrapper2
} // src_gui_kernel_qapplication
|