本文整理汇总了C++中QListWidget::setDragDropMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidget::setDragDropMode方法的具体用法?C++ QListWidget::setDragDropMode怎么用?C++ QListWidget::setDragDropMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidget
的用法示例。
在下文中一共展示了QListWidget::setDragDropMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QMenu
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]
QListWidget *listWidget = new QListWidget(this);
listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
listWidget->setDragEnabled(true);
listWidget->viewport()->setAcceptDrops(true);
listWidget->setDropIndicatorShown(true);
//! [0] //! [1]
listWidget->setDragDropMode(QAbstractItemView::InternalMove);
//! [1]
this->listWidget = listWidget;
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
setupListItems();
setCentralWidget(listWidget);
setWindowTitle(tr("List Widget"));
}
示例2: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// QListWidget
QListWidget listWidget;
// 一种添加项目的简便方法
new QListWidgetItem("a", &listWidget);
// 添加项目的另一种方法,这样还可以进行各种设置
QListWidgetItem *listWidgetItem = new QListWidgetItem;
listWidgetItem->setText("b");
listWidgetItem->setIcon(QIcon("../modelView2/yafeilinux.png"));
listWidgetItem->setToolTip("this is b!");
listWidget.insertItem(1, listWidgetItem);
// 设置排序为倒序
listWidget.sortItems(Qt::DescendingOrder);
// 显示列表部件
listWidget.show();
// QTreeWidget
QTreeWidget treeWidget;
// 必须设置列数
treeWidget.setColumnCount(2);
// 设置标头
QStringList headers;
headers << "name" << "year";
treeWidget.setHeaderLabels(headers);
// 添加项目
QTreeWidgetItem *grade1 = new QTreeWidgetItem(&treeWidget);
grade1->setText(0,"Grade1");
QTreeWidgetItem *student = new QTreeWidgetItem(grade1);
student->setText(0,"Tom");
student->setText(1,"1986");
QTreeWidgetItem *grade2 = new QTreeWidgetItem(&treeWidget, grade1);
grade2->setText(0,"Grade2");
treeWidget.show();
// QTableWidget
// 创建表格部件,同时指定行数和列数
QTableWidget tableWidget(3, 2);
// 创建表格项目,并插入到指定单元
QTableWidgetItem *tableWidgetItem = new QTableWidgetItem("qt");
tableWidget.setItem(1, 1, tableWidgetItem);
// 创建表格项目,并将它们作为标头
QTableWidgetItem *headerV = new QTableWidgetItem("first");
tableWidget.setVerticalHeaderItem(0,headerV);
QTableWidgetItem *headerH = new QTableWidgetItem("ID");
tableWidget.setHorizontalHeaderItem(0,headerH);
tableWidget.show();
// 为listWidget启用拖放
// 设置选择模式为单选
listWidget.setSelectionMode(QAbstractItemView::SingleSelection);
// 启用拖动
listWidget.setDragEnabled(true);
// 设置接受拖放
listWidget.viewport()->setAcceptDrops(true);
// 设置显示将要被放置的位置
listWidget.setDropIndicatorShown(true);
// 设置拖放模式为移动项目,如果不设置,默认为复制项目
listWidget.setDragDropMode(QAbstractItemView::InternalMove);
return app.exec();
}
示例3: setupUi
//.........这里部分代码省略.........
line_2->setObjectName(QStringLiteral("line_2"));
line_2->setFrameShape(QFrame::HLine);
line_2->setFrameShadow(QFrame::Sunken);
verticalLayout_2->addWidget(line_2);
cbMute = new QCheckBox(MVPPlayerRemoteDialog);
cbMute->setObjectName(QStringLiteral("cbMute"));
cbMute->setChecked(true);
verticalLayout_2->addWidget(cbMute);
verticalLayout = new QVBoxLayout();
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
verticalLayout->setSizeConstraint(QLayout::SetNoConstraint);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
label = new QLabel(MVPPlayerRemoteDialog);
label->setObjectName(QStringLiteral("label"));
horizontalLayout_2->addWidget(label);
lblCurrentTrack = new QLabel(MVPPlayerRemoteDialog);
lblCurrentTrack->setObjectName(QStringLiteral("lblCurrentTrack"));
QSizePolicy sizePolicy2(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(lblCurrentTrack->sizePolicy().hasHeightForWidth());
lblCurrentTrack->setSizePolicy(sizePolicy2);
lblCurrentTrack->setWordWrap(true);
horizontalLayout_2->addWidget(lblCurrentTrack);
lblTrackLength = new QLabel(MVPPlayerRemoteDialog);
lblTrackLength->setObjectName(QStringLiteral("lblTrackLength"));
lblTrackLength->setAlignment(Qt::AlignCenter);
horizontalLayout_2->addWidget(lblTrackLength);
verticalLayout->addLayout(horizontalLayout_2);
horizontalLayout_3 = new QHBoxLayout();
horizontalLayout_3->setObjectName(QStringLiteral("horizontalLayout_3"));
sliderPosition = new QSlider(MVPPlayerRemoteDialog);
sliderPosition->setObjectName(QStringLiteral("sliderPosition"));
sliderPosition->setMaximum(100);
sliderPosition->setOrientation(Qt::Horizontal);
sliderPosition->setInvertedAppearance(false);
sliderPosition->setInvertedControls(false);
sliderPosition->setTickPosition(QSlider::TicksBelow);
sliderPosition->setTickInterval(1);
horizontalLayout_3->addWidget(sliderPosition);
verticalLayout->addLayout(horizontalLayout_3);
horizontalLayout_5 = new QHBoxLayout();
horizontalLayout_5->setObjectName(QStringLiteral("horizontalLayout_5"));
btnClearPlaylist = new QToolButton(MVPPlayerRemoteDialog);
btnClearPlaylist->setObjectName(QStringLiteral("btnClearPlaylist"));
QIcon icon1;
icon1.addFile(QStringLiteral(":/mvpplayer/action/cancel.png"), QSize(), QIcon::Normal, QIcon::Off);
btnClearPlaylist->setIcon(icon1);
horizontalLayout_5->addWidget(btnClearPlaylist);
lblPlaylist = new QLabel(MVPPlayerRemoteDialog);
lblPlaylist->setObjectName(QStringLiteral("lblPlaylist"));
horizontalLayout_5->addWidget(lblPlaylist);
verticalLayout->addLayout(horizontalLayout_5);
playlist = new QListWidget(MVPPlayerRemoteDialog);
playlist->setObjectName(QStringLiteral("playlist"));
QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Maximum);
sizePolicy3.setHorizontalStretch(0);
sizePolicy3.setVerticalStretch(0);
sizePolicy3.setHeightForWidth(playlist->sizePolicy().hasHeightForWidth());
playlist->setSizePolicy(sizePolicy3);
playlist->setDragDropMode(QAbstractItemView::DropOnly);
verticalLayout->addWidget(playlist);
verticalLayout_2->addLayout(verticalLayout);
verticalLayout_4->addLayout(verticalLayout_2);
QWidget::setTabOrder(cbMute, sliderPosition);
QWidget::setTabOrder(sliderPosition, playlist);
retranslateUi(MVPPlayerRemoteDialog);
QMetaObject::connectSlotsByName(MVPPlayerRemoteDialog);
} // setupUi