Skip to content

fix: Use an event filter to avoid scrolling #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2025

Conversation

gselzer
Copy link
Contributor

@gselzer gselzer commented May 14, 2025

Following up on #432, @tlambert03 mentioned that what would be better than just ignoring scroll events would be to redirect them to the parent, since usually users want to scroll the table and not the contents. This PR uses an event filter to do just that.

Unfortunately, the sliders are still tricky, and I had to access the private _slider attribute of the SliderProxy to get it to work (as @tlambert03 foreshadowed in #432). This PR could be easily cleaned up and merged as is, but I'd prefer to spur discussion on how we make those pesky sliders behave.

Oh, and I need to fix the test I wrote for #432.

closes #372

@gselzer gselzer requested a review from tlambert03 May 14, 2025 18:36
@gselzer gselzer self-assigned this May 14, 2025
@gselzer gselzer added the bug Something isn't working label May 14, 2025
Copy link

codecov bot commented May 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.55%. Comparing base (967fa6a) to head (4bfd3e8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #433      +/-   ##
==========================================
+ Coverage   90.54%   90.55%   +0.01%     
==========================================
  Files          90       90              
  Lines        9853     9870      +17     
==========================================
+ Hits         8921     8938      +17     
  Misses        932      932              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03
Copy link
Member

we also really need this on the device property table (perhaps even more than the groups/presets editor). that's what #372 was about. Can you see if you can get this to apply when running python examples/property_browser.py and scrolling on a slider

@tlambert03
Copy link
Member

here's a self-contained QTableWidget that seems to do a good job preventing stuff bubbling up, without making assumptions about private stuff:

class NoWheelTableWidget(QTableWidget):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        self.viewport().installEventFilter(self)

    def setCellWidget(self, row: int, column: int, widget: QWidget) -> None:
        for child in widget.findChildren(
            (QAbstractSpinBox, QAbstractSlider, QComboBox)
        ):
            child.installEventFilter(self)
        widget.installEventFilter(self)
        super().setCellWidget(row, column, widget)

    def eventFilter(self, obj: QObject, event: QEvent) -> bool:
        if isinstance(event, QWheelEvent):
            # Scroll the vertical scrollbar manually, to avoid recursion error.
            if sb := self.verticalScrollBar():
                delta = event.angleDelta().y()
                sb.setValue(sb.value() - delta)
            # Consume the event so child widgets don't process it
            return True
        return super().eventFilter(obj, event)

it can be used as the base class for, e.g. DevicePropertyTable and anything else that needs it. might need some more child checks too

@gselzer
Copy link
Contributor Author

gselzer commented May 15, 2025

here's a self-contained QTableWidget that seems to do a good job preventing stuff bubbling up, without making assumptions about private stuff:

Thanks for the starter code @tlambert03! Threw it in _util.py, and extended it with both device properties and group presets. Added a test too!

Copy link
Member

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect! This definitely closes #372

is this read to go? (and if so, in the future, can you please unmark your PRs as draft when you are happy to have them merged? I read "draft" as "please do not merge this, I am still working on it and it's not yet ready for final review)

@gselzer gselzer marked this pull request as ready for review May 15, 2025 20:16
@gselzer
Copy link
Contributor Author

gselzer commented May 15, 2025

Oops, yes, ready to go!

@tlambert03 tlambert03 merged commit 0f2a345 into pymmcore-plus:main May 15, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TODO: Mouse wheel should not affect PropertyWidgets when they are embedded in a PropertyBrowser
2 participants