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
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
6using SearchBar = QWidget;
7using Element = QWidget;
8
9class Window : public QMainWindow
10{
11public:
12 Window(QWidget *parent = nullptr);
13
14protected:
15 bool event(QEvent *event) override;
16
17private:
18 Element *elementAt(QPoint pos) const {
19 return nullptr;
20 }
21
22 QToolBar *fileToolBar;
23 QMenu *fileMenu;
24
25 SearchBar *searchBar;
26};
27
28
29Window::Window(QWidget *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]
52bool Window::event(QEvent *event)
53{
54 if (event->type() == QEvent::ToolTip) {
55 QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
56 if (Element *element = elementAt(helpEvent->pos())) {
57 QToolTip::showText(helpEvent->globalPos(), element->toolTip());
58 } else {
59 QToolTip::hideText();
60 event->ignore();
61 }
62
63 return true;
64 }
65 return QWidget::event(event);
66}
67//! [dynamic_tooltip]
68
69int main(int argc, char **argv)
70{
71 QApplication app(argc, argv);
72 Window w;
73 return 0;
74}
[Window class with invokable method]
Definition window.h:11
bool event(QEvent *event) override
[dynamic_tooltip]
Definition main.cpp:52
Window(QWidget *parent=nullptr)
Definition main.cpp:29
int main(int argc, char *argv[])
[ctor_close]