-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix: Use an event filter to avoid scrolling #433
Conversation
Was already fixed
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
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 |
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. |
Thanks @tlambert03 for the suggestion/starter code
Thanks for the starter code @tlambert03! Threw it in |
There was a problem hiding this 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)
Oops, yes, ready to go! |
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 theSliderProxy
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