diff options
Diffstat (limited to 'examples/widgets/draganddrop/dropsite/dropsitewindow.cpp')
-rw-r--r-- | examples/widgets/draganddrop/dropsite/dropsitewindow.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp index 2dae83bb22..a937e24a4c 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp @@ -82,14 +82,21 @@ DropSiteWindow::DropSiteWindow() //! [constructor part4] clearButton = new QPushButton(tr("Clear")); + copyButton = new QPushButton(tr("Copy")); quitButton = new QPushButton(tr("Quit")); buttonBox = new QDialogButtonBox; buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(copyButton, QDialogButtonBox::ActionRole); +#if !QT_CONFIG(clipboard) + copyButton->setVisible(false); +#endif + buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close); connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear); + connect(copyButton, &QAbstractButton::clicked, this, &DropSiteWindow::copy); //! [constructor part4] //! [constructor part5] @@ -108,6 +115,7 @@ DropSiteWindow::DropSiteWindow() void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) { formatsTable->setRowCount(0); + copyButton->setEnabled(false); if (!mimeData) return; //! [updateFormatsTable() part1] @@ -145,5 +153,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) } formatsTable->resizeColumnToContents(0); +#if QT_CONFIG(clipboard) + copyButton->setEnabled(formatsTable->rowCount() > 0); +#endif } //! [updateFormatsTable() part4] + +void DropSiteWindow::copy() +{ +#if QT_CONFIG(clipboard) + QString text; + for (int row = 0, rowCount = formatsTable->rowCount(); row < rowCount; ++row) + text += formatsTable->item(row, 0)->text() + ": " + formatsTable->item(row, 1)->text() + '\n'; + QGuiApplication::clipboard()->setText(text); +#endif +} |