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
8
MainWindow::MainWindow()
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
//! [0]
18
QListWidget *listWidget =
new
QListWidget(
this
);
19
listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
20
listWidget->setDragEnabled(
true
);
21
listWidget->viewport()->setAcceptDrops(
true
);
22
listWidget->setDropIndicatorShown(
true
);
23
//! [0]
24
25
//! [1]
26
listWidget->setDragDropMode(QAbstractItemView::InternalMove);
27
//! [1]
28
29
this
->listWidget = listWidget;
30
31
connect(quitAction, &QAction::triggered,
this
, &QWidget::close);
32
33
setupListItems();
34
35
setCentralWidget(listWidget);
36
setWindowTitle(tr(
"List Widget"
));
37
}
38
39
void
MainWindow
::setupListItems()
40
{
41
QListWidgetItem *item;
42
item =
new
QListWidgetItem(tr(
"Oak"
), listWidget);
43
item =
new
QListWidgetItem(tr(
"Fir"
), listWidget);
44
item =
new
QListWidgetItem(tr(
"Pine"
), listWidget);
45
item =
new
QListWidgetItem(tr(
"Birch"
), listWidget);
46
item =
new
QListWidgetItem(tr(
"Hazel"
), listWidget);
47
item =
new
QListWidgetItem(tr(
"Redwood"
), listWidget);
48
item =
new
QListWidgetItem(tr(
"Sycamore"
), listWidget);
49
item =
new
QListWidgetItem(tr(
"Chestnut"
), listWidget);
50
item =
new
QListWidgetItem(tr(
"Mahogany"
), listWidget);
51
}
MainWindow
[6]
Definition
src_corelib_kernel_qmetaobject.cpp:74
qtbase
src
widgets
doc
snippets
qlistwidget-dnd
mainwindow.cpp
Generated on
for Qt by
1.18.0