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#include "model.h"
8
10{
11 QMenu *fileMenu = new QMenu(tr("&File"));
12
13 QAction *quitAction = fileMenu->addAction(tr("E&xit"));
14 quitAction->setShortcut(tr("Ctrl+Q"));
15
16 menuBar()->addMenu(fileMenu);
17
18// For convenient quoting:
20QListView *listView = new QListView(this);
22listView->setDragEnabled(true);
23listView->setAcceptDrops(true);
24listView->setDropIndicatorShown(true);
26
27 this->listView = listView;
28
29 connect(quitAction, &QAction::triggered,
30 this, &QWidget::close);
31
32 setupListItems();
33
34 setCentralWidget(listView);
35 setWindowTitle(tr("List View"));
36}
37
38void MainWindow::setupListItems()
39{
41 items << tr("Oak") << tr("Fir") << tr("Pine") << tr("Birch") << tr("Hazel")
42 << tr("Redwood") << tr("Sycamore") << tr("Chestnut")
43 << tr("Mahogany");
44
45 DragDropListModel *model = new DragDropListModel(items, this);
46 listView->setModel(model);
47}
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
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 QListView class provides a list or icon view onto a model.
Definition qlistview.h:17
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
\inmodule QtCore
bool close()
Closes this widget.
Definition qwidget.cpp:8562
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
#define tr(X)
QListView * listView
QList< QTreeWidgetItem * > items
QMenuBar * menuBar
[0]