Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
"../include/mainwindow.h"
7
#
include
"model.h"
8
9
MainWindow
::
MainWindow
()
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
//! [0]
19
QListView *listView =
new
QListView(
this
);
20
listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
21
listView->setDragEnabled(
true
);
22
listView->setAcceptDrops(
true
);
23
listView->setDropIndicatorShown(
true
);
24
//! [0]
25
26
this
->listView = listView;
27
28
connect(quitAction, &QAction::triggered,
29
this
, &QWidget::close);
30
31
setupListItems();
32
33
setCentralWidget(listView);
34
setWindowTitle(tr(
"List View"
));
35
}
36
37
void
MainWindow
::setupListItems()
38
{
39
QStringList items;
40
items << tr(
"Oak"
) << tr(
"Fir"
) << tr(
"Pine"
) << tr(
"Birch"
) << tr(
"Hazel"
)
41
<< tr(
"Redwood"
) << tr(
"Sycamore"
) << tr(
"Chestnut"
)
42
<< tr(
"Mahogany"
);
43
44
DragDropListModel *model =
new
DragDropListModel(items,
this
);
45
listView->setModel(model);
46
}
MainWindow
[6]
Definition
src_corelib_kernel_qmetaobject.cpp:74
MainWindow::MainWindow
MainWindow()
Definition
src_corelib_kernel_qobject.cpp:79
qtbase
src
widgets
doc
snippets
qlistview-dnd
mainwindow.cpp
Generated on
for Qt by
1.18.0