bool QToolBoxHelper::eventFilter(QObject *watched, QEvent *event) { switch (event->type()) { case QEvent::ChildPolished: // Install on the buttons if (watched == m_toolbox) { QChildEvent *ce = static_cast<QChildEvent *>(event); if (!qstrcmp(ce->child()->metaObject()->className(), "QToolBoxButton")) ce->child()->installEventFilter(this); } break; case QEvent::ContextMenu: if (watched != m_toolbox) { // An action invoked from the passive interactor (ToolBox button) might // cause its deletion within its event handler, triggering a warning. Re-post // the event to the toolbox. QContextMenuEvent *current = static_cast<QContextMenuEvent *>(event); QContextMenuEvent *copy = new QContextMenuEvent(current->reason(), current->pos(), current-> globalPos(), current->modifiers()); QApplication::postEvent(m_toolbox, copy); current->accept(); return true; } break; case QEvent::MouseButtonRelease: if (watched != m_toolbox) if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(m_toolbox)) { fw->clearSelection(); fw->selectWidget(m_toolbox, true); } break; default: break; } return QObject::eventFilter(watched, event); }
bool StayPoppedUpComboBox::eventFilter(QObject* o, QEvent* e) { // The combo box has installed an event filter on the view. // If it catches a valid mouse button release there, it will hide the popup. // Here we prevent this by eating the event ourselves, // and then dispatching it to its destination. if (o == m_view || o == m_view->viewport()) { switch (e->type()) { case QEvent::MouseButtonRelease: { QMouseEvent* m = static_cast<QMouseEvent*>(e); if (m_view->isVisible() && m_view->rect().contains(m->pos())) { if (o == m_view) { o->event(e); } else // Viewport: Calling event() does not work, viewportEvent() is needed. // This is the event that gets redirected to the QTreeView finally! { sendViewportEventToView(e); } // we have dispatched the event privately; we filter it out from the main dispatching return true; } break; } case QEvent::ContextMenu: { if (o != m_view) { // for whatever reason, the position of the event is slightly wrong QContextMenuEvent* m = static_cast<QContextMenuEvent*>(e); QPoint correctPos = m_view->viewport()->mapFromGlobal(m->globalPos()); QContextMenuEvent corrected(m->reason(), correctPos, m->globalPos(), m->modifiers()); sendViewportEventToView(&corrected); return true; } break; } default: break; } } return QComboBox::eventFilter(o, e); }