9MainWindow::MainWindow(QWidget *parent)
12 QFrame *centralFrame =
new QFrame(
this);
14 QLabel *nameLabel =
new QLabel(tr(
"Comment:"), centralFrame);
15 commentEdit =
new QTextEdit(centralFrame);
16 QLabel *dragLabel =
new QLabel(tr(
"<p>Drag the icon to a filer "
17 "window or the desktop background:</p>"),
19 iconLabel =
new QLabel(centralFrame);
20 iconPixmap.load(
":/images/file.png");
21 iconLabel->setPixmap(iconPixmap);
23 QGridLayout *grid =
new QGridLayout(centralFrame);
24 grid->addWidget(nameLabel, 0, 0);
25 grid->addWidget(commentEdit, 1, 0, 1, 2);
26 grid->addWidget(dragLabel, 2, 0);
27 grid->addWidget(iconLabel, 2, 1);
30 setCentralWidget(centralFrame);
31 setWindowTitle(tr(
"Dragging"));
37 if (event->button() == Qt::LeftButton
38 && iconLabel->geometry().contains(event->pos())) {
41 QDrag *drag =
new QDrag(
this);
42 QMimeData *mimeData =
new QMimeData;
44 mimeData->setText(commentEdit->toPlainText());
45 drag->setMimeData(mimeData);
47 drag->setPixmap(iconPixmap);
49 Qt::DropAction dropAction = drag->exec();
55 actionText = tr(
"The text was copied.");
58 actionText = tr(
"The text was moved.");
61 actionText = tr(
"The text was linked.");
63 case Qt::IgnoreAction:
64 actionText = tr(
"The drag was ignored.");
67 actionText = tr(
"Unknown action.");
70 statusBar()->showMessage(actionText);
void mousePressEvent(QMouseEvent *event) override
[0]