bool JumpToWidget::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::Wheel) { return QApplication::sendEvent(_view->viewport(), event); } else if (event->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (mouseEvent) { // The A-Z order has been chosen arbitrarily int v = mouseEvent->y() * 26 / height(); // in ASCII, the A letter is 65 QString s(v + 65); emit aboutToScrollTo(s); } return false; } else { return QWidget::eventFilter(obj, event); } }
bool JumpToWidget::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::Wheel) { return QApplication::sendEvent(_view->viewport(), event); } else if (event->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (mouseEvent) { // The A-Z order has been chosen arbitrarily // This Widget won't automatically adapt to non-latin languages, like Russian, Japanese hiraganas, etc. int v = mouseEvent->y() * 26 / height(); // in ASCII, the A letter is 65 QString s(v + 65); emit aboutToScrollTo(s); } return false; } else { return QWidget::eventFilter(obj, event); } }