PDA

View Full Version : Mouse Events in a widget



Rayven
4th May 2006, 21:20
Can mouse events only be captured by a class? Or can any specific widget capture an event? For instance, I have a video player window that uses a QAxWidget. This video player window has a series of buttons and sliders. I only want to capture the mouse events that occur within the actual video window itself, not the buttons.


mpVideoPlayer = new QAxWidget( mpFrame );
mpVideoPlayer->setGeometry( QRect( 0, 0, 561, 351 ) );
mpVideoPlayer->setCursor( Qt::CrossCursor );




void VideoViewerWindow::mouseReleaseEvent( QMouseEvent *event )
{
if( event->button() == Qt::LeftButton )
{
QString test = QString( event->x() ) + ", " + QString( event->y() );

QMessageBox::warning( this, tr( "Position" ), tr( "Left Button Pressed" ) );
}
else if( event->button() == Qt::RightButton )
{
QMessageBox::warning( this, tr( "Position" ), tr( "Right Button Pressed" ) );
}
}


When running this code, all events are captured no matter where in the VideoViewerWindow class. However, when I try to put mpVideoPlayer->accept() I get compile errors. Do I have to make mpVideoPlayer a subclass of QAxWidget for this to work?

Thanks

jpn
4th May 2006, 21:28
So you want to catch mpVideoPlayer's events?
Maybe you could try to install an event filter (http://doc.trolltech.com/4.1/qobject.html#installEventFilter) on it?

Rayven
5th May 2006, 15:07
Thats what I was looking for! Thanks mucho!