Ejemplo n.º 1
3
  // ! [1]
  protected void dropEvent(QDropEvent event) {
    if (event.source() == this && event.possibleActions().isSet(Qt.DropAction.MoveAction)) return;
    // ! [1]

    // ! [2]
    if (event.proposedAction().equals(Qt.DropAction.MoveAction)) {
      event.acceptProposedAction();
      // Process the data from the event.
      // ! [2]
      dragResult.emit(tr("The data was moved here."));
      // ! [3]
    } else if (event.proposedAction().equals(Qt.DropAction.CopyAction)) {
      event.acceptProposedAction();
      // Process the data from the event.
      // ! [3]
      dragResult.emit(tr("The data was copied here."));
      // ! [4]
    } else {
      // Ignore the drop.
      return;
    }
    // ! [4]
    // End of quote

    mimeTypes.emit(event.mimeData().formats());
    setData(
        event.mimeData().formats().get(0),
        event.mimeData().data(event.mimeData().formats().get(0)));
    // ! [5]
  }
Ejemplo n.º 2
0
  // ! [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]
  }