ich habe folgendes Problem: da im QMainWindow das Verschieben des Splitters nicht im Non-Opaque-Modus möglich ist und da die Lösung mit SetUpdatesEnabled() wahrscheinlich aufgrund Thread-Unsicherheits nicht funktioniert, dachte ich mir, ich speichere die Mouse-Events in einem EventFilter und schicke dann nur den MousePress, einen (kompletten, statt vielen kleinen) MouseMove Event und den MouseRelease Event. Aber irgendwie kommen die mit sendEvent() gesendeten Events nicht an, es geschieht rein gar nichts.
Hier der Code:
Code: Alles auswählen
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 );
}
kann mir jemand sagen, warum das nicht funktioniert?
Bin für jede Hilfe dankbar!