PDA

View Full Version : parent widet does not get mouse event.



babu198649
27th July 2008, 06:40
hi
In the following code ,the mousePressEvent is not executed.does this means that the events first goes to child widgets and then to parents.


#include <QtGui>
class Widget : public QMainWindow
{
public:
Widget()
{
QDirModel *model = new QDirModel;
QListView *list =new QListView(this);
list->setModel(model);
this->setCentralWidget(list);
}

protected:
void mousePressEvent(QMouseEvent *event)
{
qDebug()<<"press";
}
};


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}

jpn
27th July 2008, 08:43
In the following code ,the mousePressEvent is not executed.does this means that the events first goes to child widgets and then to parents.
That's right. Ignoring the event, however, indicates that the receiver does not want the event. Unwanted events might be propagated to the parent widget. Also, event filters make it possible to catch events of arbitrary receivers.