{
static bool bInternalSend = false;
if ( !bInternalSend )
{
if ( pEvent
->type
() == QEvent::MouseButtonPress ) {
QMouseEvent *pMouseEvent
= dynamic_cast<QMouseEvent
*>
(pEvent
);
if ( pMouseEvent )
cStartEvent = *pMouseEvent;
this->StartRubberBand(); // show the rubber band at the current mouse position, depending on the mouse cursor shape
return true;
}
else if ( pEvent
->type
() == QEvent::MouseButtonRelease ) {
this->EndRubberBand(); // hide the rubber band
QMouseEvent *pMouseEvent
= dynamic_cast<QMouseEvent
*>
(pEvent
);
if ( pMouseEvent )
{
bInternalSend = true;
QApplication::sendEvent( this,
&cStartEvent
);
// send mouse press event bInternalSend = true;
QApplication::sendEvent( this,
&cLastMoveEvent
);
// send last mouse move event }
}
else if ( pEvent
->type
() == QEvent::MouseMove ) {
QMouseEvent *pMouseEvent
= dynamic_cast<QMouseEvent
*>
(pEvent
);
if ( pMouseEvent )
cLastMoveEvent = *pMouseEvent;
this->MoveRubberBand(); // move the rubber band to the new mouse position
return true;
}
}
bInternalSend = false;
}
bool MyMainWindow::eventFilter( QObject *pObj, QEvent *pEvent )
{
static bool bInternalSend = false;
static QMouseEvent cStartEvent(QEvent::MouseButtonPress, QCursor::pos(), Qt::MouseButton::LeftButton, 0, 0 );
static QMouseEvent cLastMoveEvent(QEvent::MouseMove, QCursor::pos(), Qt::MouseButton::LeftButton, 0, 0 );
if ( !bInternalSend )
{
if ( pEvent->type() == QEvent::MouseButtonPress )
{
QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
if ( pMouseEvent )
cStartEvent = *pMouseEvent;
this->StartRubberBand(); // show the rubber band at the current mouse position, depending on the mouse cursor shape
return true;
}
else if ( pEvent->type() == QEvent::MouseButtonRelease )
{
this->EndRubberBand(); // hide the rubber band
QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
if ( pMouseEvent )
{
bInternalSend = true;
QApplication::sendEvent( this, &cStartEvent ); // send mouse press event
bInternalSend = true;
QApplication::sendEvent( this, &cLastMoveEvent ); // send last mouse move event
}
}
else if ( pEvent->type() == QEvent::MouseMove )
{
QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
if ( pMouseEvent )
cLastMoveEvent = *pMouseEvent;
this->MoveRubberBand(); // move the rubber band to the new mouse position
return true;
}
}
bInternalSend = false;
return QMainWindow::eventFilter( pObj, pEvent );
}
To copy to clipboard, switch view to plain text mode
Bookmarks