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
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
8MainWindow::MainWindow()
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{
30 setToolButtonStyle(Qt::ToolButtonTextOnly);
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
47//! [0]
48 QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this);
49 dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
50 Qt::RightDockWidgetArea);
51 dockWidget->setWidget(dockWidgetContents);
52 addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
53//! [0]
54}