Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
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
30 : QMainWindow(parent)
31{
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);
42
44 searchBar = new SearchBar;
45 searchBar->setToolTip(tr("Search in the current document"));
47
48 fileToolBar->addWidget(searchBar);
49}
50
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 {
60 event->ignore();
61 }
62
63 return true;
64 }
65 return QWidget::event(event);
66}
68
69int main(int argc, char **argv)
70{
71 QApplication app(argc, argv);
72 Window w;
73 return 0;
74}
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
The QApplication class manages the GUI application's control flow and main settings.
\inmodule QtCore
Definition qcoreevent.h:45
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:788
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition qevent.h:799
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition qevent.h:798
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
QAction * addMenu(QMenu *menu)
Appends menu to the menu bar.
Definition qmenubar.cpp:768
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QToolBar class provides a movable panel that contains a set of controls.
Definition qtoolbar.h:23
QAction * addWidget(QWidget *widget)
Adds the given widget to the toolbar as the toolbar's last item.
Definition qtoolbar.cpp:792
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr, const QRect &rect={}, int msecShowTime=-1)
Shows text as a tool tip, with the global position pos as the point of interest.
Definition qtooltip.cpp:439
static void hideText()
Definition qtooltip.h:19
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
[Window class with invokable method]
Definition window.h:11
bool event(QEvent *event) override
[dynamic_tooltip]
Definition main.cpp:52
Window()
Definition window.cpp:6
int main()
[0]
GLfloat GLfloat GLfloat w
[0]
struct _cl_event * event
QWidget SearchBar
Definition main.cpp:6
#define tr(X)
QApplication app(argc, argv)
[0]
QMenuBar * menuBar
[0]