PDA

View Full Version : eventFilter: pop-up custom widget



vonCZ
22nd November 2007, 09:48
'morning,

I have a custom QWidget, myWid, that pops up when the user mouses over a QPushButton. The QWidget pops-up adjacent to (slightly overlapping) this pushButton. I want myWid to remain shown (popped up) as long as the mouse is over either the QPushButton *or* myWid. My eventFilter looks like this:



bool Window::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::Enter)
{
if(obj == myPB)
{
myWid->show();
return QWidget::eventFilter(obj, event);
}
return QWidget::eventFilter(obj, event);

else if(event->type() == QEvent::Leave)
{
if(obj == myPB)
{
if(!myWid->underMouse())
{
myWid->hide();
return QWidget::eventFilter(obj, event);
}
return QWidget::eventFilter(obj, event);
}
return QWidget::eventFilter(obj, event);
}
return QWidget::eventFilter(obj, event);
}

the "hide()" above is conditional: if the mouse is over myWid, do not hide() it when Leave myPB. This doesn't work: the panel flickers on/off rapidly or closes when I mouse over it. I understand why this is happening, but I can't figure out an alternative. Suggestions?

wysota
22nd November 2007, 09:54
You can use a timer to hide the popup. This way you'll manage to receive an enter event on the popup before it gets closed. You can then stop the timer so that it doesn't trigger hide(). I think that has a chance to work.

An alternative would be to react on help event instead - this way your popup would behave exactly as a tooltip.