summaryrefslogtreecommitdiffstats
path: root/tests/manual/widgets/widgets/multiscreen-menus/mainwindow.cpp
blob: ec3b4085a3b99aa84916bd1ff6bf60753da5a036 (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui/QtEvents>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setStyleSheet("QMenu { menu-scrollable: 0 }");

    auto *mb = new QMenuBar(this);
    setMenuBar(mb);

    auto *m = new QMenu(mb);
    m->setTitle("&Menu");
    m->setTearOffEnabled(true);

    for (int i = 0; i < 80; ++i)
        m->addAction("Menu Item #" + QString::number(i));

    mb->addMenu(m);

    ui->menuButton->setMenu(m);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::contextMenuEvent(QContextMenuEvent *e)
{
    const auto *mb = menuBar();
    mb->actions().first()->menu()->popup(mb->mapToGlobal(e->pos()));
}