C++ (Qt)while (IsMouseDown()) { QPoint pt = GetMousePosition(); if (pt != oldPt) DragSomething(pt); oldPt = pt;}
C++ (Qt)extern bool isDragging = false; bool IsMouseStillDown( void ){ if (!isDragging) { qApp->installEventFilter(&myFilter); isDragging = true; } qApp->processEvents(QEventLoop::WaitForMoreEvents); if (!isDragging) qApp->removeEventFilter(&myFilter); return isDragging;}
::onMousePressed(MouseEvent *e): m_clickPosition = e->pos(); m_objectDragged = findObjectAt(m_clickPosition); m_isDrag = true;::onMouseReleased(MouseEvent *e): hangleRelease(e->pos(), m_objectDragged); m_isDrag = false;::onMouseMoved(MouseEvent *e): if (m_isDrag) handleDrag(e->pos(), m_objectDragged)
::onMousePressed(MouseEvent *e){ m_clickPosition = e->pos(); m_objectDragged = findObjectAt(m_clickPosition); m_isDrag = true; m_oldPosition = e->pos(); installFilter(this); while (m_isDrag) { if (m_oldPosition != m_lastEvent ->pos()) { m_oldPosition = m_lastEvent ->pos(); hangleDrag(m_lastEvent , m_oldPosition); } qApp->processEvents(); msleep(...); } uninstallFilter(this); hangleRelease(m_lastEvent ->pos(), m_objectDragged);}::onMouseReleased(MouseEvent *e){ m_lastEvent = e; m_isDrag = false;}::onMouseMoved(MouseEvent *e){ if (m_isDrag) m_lastEvent = e;}