Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
include
<
QtWidgets
>
5
6
using
SearchBar = QWidget;
7
using
Element = QWidget;
8
9
class
Window
:
public
QMainWindow
10
{
11
public
:
12
Window
(QWidget *parent =
nullptr
);
13
14
protected
:
15
bool
event
(QEvent *event)
override
;
16
17
private
:
18
Element *elementAt(QPoint pos)
const
{
19
return
nullptr
;
20
}
21
22
QToolBar *fileToolBar;
23
QMenu *fileMenu;
24
25
SearchBar *searchBar;
26
};
27
28
29
Window
::
Window
(QWidget *parent)
30
:
QMainWindow
(
parent
)
31
{
32
//! [action_tooltip]
33
QAction *openAction =
new
QAction(tr(
"&Open..."
));
34
openAction->setToolTip(tr(
"Open an existing file"
));
35
36
fileMenu = menuBar()->addMenu(tr(
"&File"
));
37
fileToolBar = addToolBar(tr(
"&File"
));
38
39
fileMenu->addAction(openAction);
40
fileToolBar->addAction(openAction);
41
//! [action_tooltip]
42
43
//! [static_tooltip]
44
searchBar =
new
SearchBar;
45
searchBar->setToolTip(tr(
"Search in the current document"
));
46
//! [static_tooltip]
47
48
fileToolBar->addWidget(searchBar);
49
}
50
51
//! [dynamic_tooltip]
52
bool
Window
::
event
(QEvent *event)
53
{
54
if
(event->type() == QEvent::ToolTip) {
55
auto
*helpEvent =
static_cast
<QHelpEvent *>(event);
56
if
(Element *element = elementAt(helpEvent->pos())) {
57
QToolTip::showText(helpEvent->globalPos(), element->toolTip(),
this
);
58
}
else
{
59
QToolTip::hideText();
60
event->ignore();
61
}
62
63
return
true
;
64
}
65
return
QWidget::event(event);
66
}
67
//! [dynamic_tooltip]
68
69
int
main
(
int
argc,
char
**argv)
70
{
71
QApplication app(argc, argv);
72
Window
w;
73
return
0;
74
}
Window
[Window class with invokable method]
Definition
window.h:11
Window::event
bool event(QEvent *event) override
[dynamic_tooltip]
Definition
main.cpp:52
Window::Window
Window(QWidget *parent=nullptr)
Definition
main.cpp:29
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtbase
src
widgets
doc
snippets
tooltips
main.cpp
Generated on
for Qt by
1.18.0