コード例 #1
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]
  }
コード例 #2
0
 @Override
 protected void mouseReleaseEvent(QMouseEvent event) {
   if (event.button() == Qt.MouseButton.LeftButton && scribbling) {
     drawLineTo(event.pos());
     scribbling = false;
   }
 }
コード例 #3
0
 @Override
 protected void mousePressEvent(QMouseEvent event) {
   if (event.button() == Qt.MouseButton.LeftButton) {
     lastPoint = event.pos();
     scribbling = true;
   }
 }
コード例 #4
0
 // ! [6]
 protected void mousePressEvent(QMouseEvent event) {
   if (event.button().equals(Qt.MouseButton.LeftButton)) dragStartPosition = event.pos();
 }
コード例 #5
0
 @Override
 protected void mouseMoveEvent(QMouseEvent event) {
   if ((event.buttons().isSet(Qt.MouseButton.LeftButton)) && scribbling) drawLineTo(event.pos());
 }