Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox should ignore wheel events, but parent widget should use them for QScrollArea
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cryst
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cryst
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved