PDA

View Full Version : undermouse() function not working



babu198649
6th November 2007, 14:42
hi
i have a Qstackedwidget in which Qlistview and Qlabel are added . i have subclassed the main class which contains Qstackedwidget to receive mousepress events

inside the mousepress event i have if statement like this

QStackedWidget *stackedwidget;
if(stackedwidget->underMouse())
cout<<"hi";

when the label is under mouse it works fine ,but when Qlistview is under mouse it doesnot detect. is it possible to make it right.

thanks

wysota
6th November 2007, 15:44
Retrieve the event position from the event object and then test whether the rect() of the class contains the position of the event, like so:

void someClass::mousePressEvent(QMouseEvent *me){
QPoint pos = me->pos();
if(stackedwidget->rect().contains(pos)){
qDebug("STACK WIDGET HERE");
}
}

Note that this will not work if the child widget you want to test against handles the mouse press event itself (like QListView probably does). In that situation you have to reimplement the event in the widget in question or apply an event filter on the child widget to monitor its events. See the docs for reference on event filters.

babu198649
7th November 2007, 11:02
thank u wysota
is there any way to stop all the widgets in the main window receiving events
and all the events should be send by mainwindow.
i know event filter may do this but main window must require knowledge of its child widgets, is it possible to stop the events of the childs without the knowldege of the number of childs the main window has.

momesana
7th November 2007, 14:32
AFAIK you can get *all* events by installing the eventfilter on qApp. This way you could get all events from all widgets. Be sure to pass on the events you are not interested in.