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
mainwindow.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 <QtWidgets>
5
6#include "mainwindow.h"
7
9{
10 QMenu *fileMenu = new QMenu(tr("&File"));
11
12 QAction *quitAction = fileMenu->addAction(tr("E&xit"));
13 quitAction->setShortcut(tr("Ctrl+Q"));
14
15 menuBar()->addMenu(fileMenu);
16
17// For convenient quoting:
19QListWidget *listWidget = new QListWidget(this);
21listWidget->setDragEnabled(true);
22listWidget->viewport()->setAcceptDrops(true);
23listWidget->setDropIndicatorShown(true);
25listWidget->setDragDropMode(QAbstractItemView::InternalMove);
27
28 this->listWidget = listWidget;
29
30 connect(quitAction, &QAction::triggered, this, &QWidget::close);
31
32 setupListItems();
33
34 setCentralWidget(listWidget);
35 setWindowTitle(tr("List Widget"));
36}
37
38void MainWindow::setupListItems()
39{
41 item = new QListWidgetItem(tr("Oak"), listWidget);
42 item = new QListWidgetItem(tr("Fir"), listWidget);
43 item = new QListWidgetItem(tr("Pine"), listWidget);
44 item = new QListWidgetItem(tr("Birch"), listWidget);
45 item = new QListWidgetItem(tr("Hazel"), listWidget);
46 item = new QListWidgetItem(tr("Redwood"), listWidget);
47 item = new QListWidgetItem(tr("Sycamore"), listWidget);
48 item = new QListWidgetItem(tr("Chestnut"), listWidget);
49 item = new QListWidgetItem(tr("Mahogany"), listWidget);
50}
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
The QListWidgetItem class provides an item for use with the QListWidget item view class.
Definition qlistwidget.h:23
The QListWidget class provides an item-based list widget.
void setCentralWidget(QWidget *widget)
Sets the given widget to be the main window's central widget.
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
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
bool close()
Closes this widget.
Definition qwidget.cpp:8562
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
#define tr(X)
QGraphicsItem * item
QMenuBar * menuBar
[0]