summaryrefslogtreecommitdiffstats
path: root/src/widgets/doc/snippets/mainwindowsnippet.cpp
blob: f26b66f2cc60eb30a3fd951749a40e2a6ac39fb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QtGui>

#include "mainwindow.h"

MainWindow::MainWindow()
{
    createMenus();
    createToolBars();
    createDockWidgets();
    //setMenuWidget(new QPushButton("Hello"));
}

void MainWindow::createMenus()
{
    //setMenuWidget(new QPushButton("Hello"));
    QMenu *menu = new QMenu("File");
    menu->addAction("Save &As");

    QMenuBar *bar = new QMenuBar;
    bar->addMenu(menu);

    setMenuWidget(new QWidget());
}

void MainWindow::createToolBars()
{
    setToolButtonStyle(Qt::ToolButtonTextOnly);
    QToolBar *t1 = new QToolBar;
    t1->addAction(new QAction("t1", this));

    QToolBar *t2 = new QToolBar;
    t2->addAction(new QAction("t2", this));

    addToolBar(Qt::LeftToolBarArea, t1);
    addToolBar(Qt::LeftToolBarArea, t2);
}

void MainWindow::createDockWidgets()
{
    QWidget *dockWidgetContents = new QWidget;
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(new QPushButton("My Button."));
    dockWidgetContents->setLayout(layout);

//! [0]
    QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this);
    dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
                                Qt::RightDockWidgetArea);
    dockWidget->setWidget(dockWidgetContents);
    addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
//! [0]
}