blob: e87df93ebf66e59c1c38feeb680d05f76ea28c1e (
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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
#include "mainwindow.h"
#include "model.h"
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu(tr("&File"));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(tr("Ctrl+Q"));
menuBar()->addMenu(fileMenu);
// For convenient quoting:
//! [0]
QListView *listView = new QListView(this);
listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
listView->setDragEnabled(true);
listView->setAcceptDrops(true);
listView->setDropIndicatorShown(true);
//! [0]
this->listView = listView;
connect(quitAction, &QAction::triggered,
this, &QWidget::close);
setupListItems();
setCentralWidget(listView);
setWindowTitle(tr("List View"));
}
void MainWindow::setupListItems()
{
QStringList items;
items << tr("Oak") << tr("Fir") << tr("Pine") << tr("Birch") << tr("Hazel")
<< tr("Redwood") << tr("Sycamore") << tr("Chestnut")
<< tr("Mahogany");
DragDropListModel *model = new DragDropListModel(items, this);
listView->setModel(model);
}
|