PDA

View Full Version : Accessing Event Arguments?



BnMcG
16th December 2012, 17:26
Hi all,

In C#, when using an event handler, it will have a specific name (eg: "onPressEvent mouseclick()" - and you can then access various properties by calling mouseclick.etc() - in C++/QT I have:


void MapViewer::mousePressEvent(QMouseEvent *event)

However, I don't know how to access event or any of its methods, like documented here: http://doc.qt.digia.com/qt/qmouseevent.html#public-functions

Can anybody shed any light on this?

Regards,
Ben.

pkj
16th December 2012, 18:28
class QMouseEvent has been passed as an argument. Use it to access properties of QMouseEvent.
Supposing MapViewer is a subclass of QWidget and you have reimplemented the mousePressEvent, then all the mouse press events on widget will have your reimplemented function called.

anda_skoa
19th December 2012, 13:37
As pkj said, you have the event as a function argument and it is a normal object, so methods are called like on any other C++ object


QPoint position = event->pos(); // where inside your widget the press happend

switch ( event->button() ) {
case Qt::LeftButton: // left button pressed
break;
case Qt::RightButton: // right button pressed
break;
case Qt:MiddleButton: // middle button pressed
break;

default: // dont care
break;
}


Cheers,
_