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
mainwindowsnippet.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 <QtGui>
5
6#include "mainwindow.h"
7
9{
10 createMenus();
11 createToolBars();
12 createDockWidgets();
13 //setMenuWidget(new QPushButton("Hello"));
14}
15
16void MainWindow::createMenus()
17{
18 //setMenuWidget(new QPushButton("Hello"));
19 QMenu *menu = new QMenu("File");
20 menu->addAction("Save &As");
21
22 QMenuBar *bar = new QMenuBar;
23 bar->addMenu(menu);
24
25 setMenuWidget(new QWidget());
26}
27
28void MainWindow::createToolBars()
29{
31 QToolBar *t1 = new QToolBar;
32 t1->addAction(new QAction("t1", this));
33
34 QToolBar *t2 = new QToolBar;
35 t2->addAction(new QAction("t2", this));
36
37 addToolBar(Qt::LeftToolBarArea, t1);
38 addToolBar(Qt::LeftToolBarArea, t2);
39}
40
41void MainWindow::createDockWidgets()
42{
43 QWidget *dockWidgetContents = new QWidget;
44 QVBoxLayout *layout = new QVBoxLayout(dockWidgetContents);
45 layout->addWidget(new QPushButton("My Button."));
46
48 QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this);
51 dockWidget->setWidget(dockWidgetContents);
52 addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
54}
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition qdockwidget.h:20
void setAllowedAreas(Qt::DockWidgetAreas areas)
void setWidget(QWidget *widget)
Sets the widget for the dock widget to widget.
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition qlayout.cpp:186
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
The QMenuBar class provides a horizontal menu bar.
Definition qmenubar.h:20
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
friend class QWidget
Definition qobject.h:382
The QToolBar class provides a movable panel that contains a set of controls.
Definition qtoolbar.h:23
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
QPushButton
[1]
@ RightDockWidgetArea
@ LeftDockWidgetArea
@ LeftToolBarArea
@ ToolButtonTextOnly
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
#define t2
#define tr(X)
QDockWidget * dockWidget
[0]
QMenu menu
[5]