// ! [7] protected void mouseMoveEvent(QMouseEvent event) { if (!(event.buttons().isSet(Qt.MouseButton.LeftButton))) return; if ((event.pos().subtract(dragStartPosition)).manhattanLength() < QApplication.startDragDistance()) return; QDrag drag = new QDrag(this); QMimeData mimeData = new QMimeData(); mimeData.setData(mimeType, data); drag.setMimeData(mimeData); Qt.DropAction dropAction = drag.exec(Qt.DropAction.CopyAction, Qt.DropAction.MoveAction); // ! [7] switch (dropAction) { case CopyAction: dragResult.emit(tr("The text was copied.")); break; case MoveAction: dragResult.emit(tr("The text was moved.")); break; default: dragResult.emit(tr("Unknown action.")); break; } // ! [8] }
@Override protected void mouseReleaseEvent(QMouseEvent event) { if (event.button() == Qt.MouseButton.LeftButton && scribbling) { drawLineTo(event.pos()); scribbling = false; } }
@Override protected void mousePressEvent(QMouseEvent event) { if (event.button() == Qt.MouseButton.LeftButton) { lastPoint = event.pos(); scribbling = true; } }
// ! [6] protected void mousePressEvent(QMouseEvent event) { if (event.button().equals(Qt.MouseButton.LeftButton)) dragStartPosition = event.pos(); }
@Override protected void mouseMoveEvent(QMouseEvent event) { if ((event.buttons().isSet(Qt.MouseButton.LeftButton)) && scribbling) drawLineTo(event.pos()); }