mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-07-14 07:21:07 +02:00
fix: differentiate click and drag for DeviceItem, adapt tests accordingly
This fixes the blocking "QDrag.exec_()" on Linux, indeed before the drag'n'drop operation was started with a simple click and it was waiting for drop forever. Now there are 2 different cases, click or drag'n'drop - the drag'n'drop test actually moves the mouse and releases the button.
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING
|
||||
from bec_lib.logger import bec_logger
|
||||
from qtpy.QtCore import QMimeData, Qt
|
||||
from qtpy.QtGui import QDrag
|
||||
from qtpy.QtWidgets import QHBoxLayout, QLabel, QWidget
|
||||
from qtpy.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from qtpy.QtGui import QMouseEvent
|
||||
@@ -16,6 +16,9 @@ logger = bec_logger.logger
|
||||
class DeviceItem(QWidget):
|
||||
def __init__(self, device: str) -> None:
|
||||
super().__init__()
|
||||
|
||||
self._drag_pos = None
|
||||
|
||||
self.device = device
|
||||
layout = QHBoxLayout()
|
||||
layout.setContentsMargins(10, 2, 10, 2)
|
||||
@@ -32,12 +35,21 @@ class DeviceItem(QWidget):
|
||||
)
|
||||
|
||||
def mousePressEvent(self, event: QMouseEvent) -> None:
|
||||
super().mousePressEvent(event)
|
||||
if event.button() == Qt.LeftButton:
|
||||
drag = QDrag(self)
|
||||
mime_data = QMimeData()
|
||||
mime_data.setText(self.device)
|
||||
drag.setMimeData(mime_data)
|
||||
drag.exec_(Qt.MoveAction)
|
||||
self._drag_pos = event.pos()
|
||||
|
||||
def mouseMoveEvent(self, event: QMouseEvent) -> None:
|
||||
if not (event.buttons() and Qt.LeftButton):
|
||||
return
|
||||
if (event.pos() - self._drag_pos).manhattanLength() < QApplication.startDragDistance():
|
||||
return
|
||||
|
||||
drag = QDrag(self)
|
||||
mime_data = QMimeData()
|
||||
mime_data.setText(self.device)
|
||||
drag.setMimeData(mime_data)
|
||||
drag.exec_(Qt.MoveAction)
|
||||
|
||||
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
|
||||
logger.debug("Double Clicked")
|
||||
|
||||
Reference in New Issue
Block a user