PDA

View Full Version : Qmouseevent problem



ready
21st March 2011, 15:27
I read the documentation but couldn't figure out this constructor of QMouseevent
QMouseEvent::QMouseEvent ( Type type, const QPoint & position, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );

I want to know what is meant by const QPoint& position in this case and what value should i provide to call the constructor

high_flyer
21st March 2011, 15:31
I read the documentation but couldn't figure out this constructor of QMouseevent
what part of:

The position is the mouse cursor's position relative to the receiving widget.
didn't you understand?


I want to know what is meant by const QPoint& position in this case and what value should i provide to call the constructor
Unless you are overriding some low level Qt stuff, or some similar evil things, you should not have the need to construct your own mouse events - you should get them from the system.

Maybe if you tell us what you want to achieve we can help you in the right direction.

ready
21st March 2011, 15:56
actually I want to get mouse coordinate when I click in the picture that I loaded in my ui application using Qlabel

high_flyer
21st March 2011, 15:59
then you only need to overload the mouse event handler, or install and event filter on the QLabel.
You do NOT need to create the mouse event object.

ready
21st March 2011, 16:17
then you only need to overload the mouse event handler, or install and event filter on the QLabel.
please elaborate your explanation .........
how to install and event filter on the QLabel

high_flyer
21st March 2011, 16:25
http://doc.qt.nokia.com/latest/qobject.html#installEventFilter

ready
22nd March 2011, 05:51
I am getting really confused please help me how to install installEventFilter for Qlabel........
I just want to get the co-ordinate in my lineedit when I click in qlabel

stampede
22nd March 2011, 07:38
Which part of documentation is not clear to you ?
In order to install event filter on a QLabel you need to call:


MyClass * filterObject = new MyClass(); // MyClass is a subclass of QObject
...
QLabel * label = new QLabel();
label->installEventFilter(filterObject);

After that you will be able to catch all the events that goes to label object by reimplementing virtual bool eventFilter( QObject * obj, QEvent * ev ) (http://doc.qt.nokia.com/latest/qobject.html#eventFilter) in filterObject class:

bool MyClass::eventFilter(QObject *obj, QEvent *event)
{
if (obj == label) {
//... test if the event is MousePress and do something with it
} else {
// pass it to the parent class
return QObject::eventFilter(obj, event);
}
}
I've almost copied the example from docs.