QComboBox should ignore wheel events, but parent widget should use them for QScrollArea



  • Hi guys,

    I've got some QComboBoxes in a QScrollArea and I don't want the QComboBoxes values' to be changed by mouse wheel turns, so I wrote the following event filter:

    @
    bool CreateProblemDialog::eventFilter(QObject *object, QEvent *event)
    {
    if (event->type() == QEvent::Wheel)
    return true;
    else
    return QDialog::eventFilter(object, event);
    }
    @

    It does its job just fine, so mouse scrolls don't change the value of a QComboBox, but when I am now hovering a QComboBox the mouse wheel events aren't used for scrolling the QScrollArea up and down (they just have no effect at all). First when I stop to hover the QComboBox the mouse wheel events will be used for the QScrollArea.

    I guess I have to somehow stop the events from propergating to the QComboBoxes in the first place. I also tried to set the focus of the Combo boxes to NoFocus and ClickFocus with no result.

    Has anyone an idea how to stop propergating the wheel events and use them for the scroll area?

    Thanks in advance,
    Chris



  • Worked out a solution for this problem (rather a hack), but I still going to post it here:

    @bool CreateProblemDialog::eventFilter(QObject *object, QEvent *event)
    {
    if (event->type() == QEvent::Wheel)
    {
    QWheelEvent wheelEvent = dynamic_cast<QWheelEvent>(event);
    QApplication::sendEvent(ui->scrollArea, wheelEvent);
    return true;
    }
    else
    return QDialog::eventFilter(object, event);
    }@

    Please feel free to post anything better.

    Thanks,
    Chris


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.