PDA

View Full Version : QStackerWidget and mouse events



high_flyer
25th April 2006, 19:23
Hi,
(Qt4 SUSE 10)
I have a QStackedWidget with several widgets in it, on top of another widget that serves as a dialog.
But I can't trap the mouse button clicks on the QStackedWidget or the current visible widget in it.
In order to see the event traffic, I installed an event filter for the QStackedWidget on the dialog widget, and I show there all events that the event filter gets, and in deed, mouse button clickes just don't get trapped in the event filter.
I turned on mouse tracking, I made sure the QStackedWidget is enabled (same with its children) I even turened on mouse grabbing - the result is always the same.
I get mouse enter and mouse leave events, and the right mouse button click is trapped as context menu event, wheel events,some move move events when i get on the widget (but this stops after few move events?!) but no mouse buttn press events.
Can some one tell me what I am I missing here?
Maybe there is some option I need to turn on/off that I am no aware of?

Here is some of the relevant code:


m_widgetStack = new QStackedWidget(this);
m_tabR = new tabR();
m_tabP = new tabP();
m_tabS = new tabS();
m_tabT = new tabT();
m_widgetStack->setGeometry(m_sMenu->width(),0,this->width()-m_sMenu->width(),this->height());
m_widgetStack->addWidget(m_tabR);
m_widgetStack->addWidget(m_tabP);
m_widgetStack->addWidget(m_tabS);
m_widgetStack->addWidget(m_tabT);


m_widgetStack->grabMouse();
m_widgetStack->setEnabled(true);
m_widgetStack->setMouseTracking(true);
m_widgetStack->setFocusPolicy( Qt::StrongFocus);
m_widgetStack->installEventFilter(this);



bool MainDlg::eventFilter(QObject *obj,QEvent *event)
{
qDebug("MainDlg::eventFilter %d",event->type());
switch(event->type())
{
case QEvent::MouseButtonPress :qDebug("keyPress");
return true;
break;
case QEvent::MouseButtonRelease: qDebug("keyRelease");
return true;
break;
default: return false;
}
}


I thought maybe I need to work with the child widgets of the QStackedWidget, so I insatalled the event filter on the first child widget (the first which is visible) and the result is the same...

Any pointers (such as "did you make sure that...") or help will be very appretiated.
Thanks.

jacek
25th April 2006, 20:07
Where did you try to click?

jpn
25th April 2006, 20:11
Mouse events go directly to the child widget under the cursor and the parent widget does not receive the event if child widget handles it. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

I think you might need to install event filter more deeper level (to an invidual "bottom level" widgets, eg. widgets inside the widgets in the stack.. how horrible sentence is that) in order to receive all possible mouse events.

high_flyer
25th April 2006, 20:25
Thanks for the replys, I found the problem...
I had on each widget in the stacked widget a goupbox that grouped all the controls, and the group box was getting all the mouse vents, but I was not quering the events of the group box (I just forgot I had that group box)...

Thanks.