eventFilter: test if enter a subWidget in my subclassed QWidget
I've subclassed QWidget to make a button panel: BuPan. BuPan consists of buttons, a slider, and checkBoxes: it's a small panel that pops up next to a QPushButton in my mainApplication like so:
Code:
{
if(event
->type
() == QEvent::Enter) {
if(obj == myQPushButton)
{
myBuPan->move(xloc, yloc);
myBuPan->show();
return QWidget::eventFilter(obj, event
) }
etc...
}
pb[0] is a button in myBuPan. I want to check for an Enter event on this particular button within BuPan; I thought I could do the following:
Code:
{
if(event
->type
() == QEvent::Enter) {
if(obj == myQPushButton)
{
myBuPan->move(xloc, yloc);
myBuPan->show();
return QWidget::eventFilter(obj, event
);
}
if(obj == myBuPan->get_pb(0))
{
qDebug("HIT!!");
return QWidget::eventFilter(obj, event
);
}
etc...
// ...and I have the following in bupan.h:
QList<QPushButton *> pb;
Shouldn't this work? ...er, it's not.:o ...ideas?
Or will I have to add an "enterEvent(QEvent *event)" method to the BuPan class itself? If I have to do this second option: How can I write the bupan "enterEvent" method so that it's generic... for example, so that pb[0] and pb[2] will capture enterEvents on one instance of BuPan, but on another instance only pb[4] might capture the events?
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
You can either install the window as event filter for BuPan and the button inside BuPan, and leave your code like it is now, or(better), install BuPan as event filter for the button, and create an eventFilter for BuPan.
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
Quote:
Originally Posted by
marcel
You can either install the window as event filter for BuPan and the button inside BuPan, and leave your code like it is now,
thanks Marcel. The reason it wasn't working: I didn't installEventFilter() properly. Working now.
Quote:
Originally Posted by
marcel
or(better), install BuPan as event filter for the button, and create an eventFilter for BuPan.
I'm still not sure how to do it this way. Currently--in my mainApplication eventFilter ("Window")--I include events to filter in by referencing specific widget-objects to test whether the mouse enters/leaves the objects. But I don't know how to create an eventFilter for a subclassed QWidget that would be flexible. For example, some of my BuPan instances will have 10+ buttons, none of which need to be filtered, whereas other BuPans might have 7 buttons, half of which need to be filtered, etc...
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
I'd suggest intercepting QEvent::ToolTip instead of QEvent::Enter...
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
Quote:
Originally Posted by
wysota
I'd suggest intercepting QEvent::ToolTip instead of QEvent::Enter...
Just for curiosity and my better understanding. Can you explain the reason for this ?
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
Quote:
Originally Posted by
Gopala Krishna
Just for curiosity and my better understanding. Can you explain the reason for this ?
So that you can eliminate "accidental" hovering.
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
Quote:
Originally Posted by
marcel
So that you can eliminate "accidental" hovering.
Sorry for posting out of topic but one final question. Is this accidental hovering prevented by using timers , while sending Tooltip event ?
Re: eventFilter: test if enter a subWidget in my subclassed QWidget
Yes, most likely. On enter a timer is started and on leave the timer is disabled.
When and if the timer triggers, the tooltip event is posted.