Skip to content
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

Update SmoothScrollDelegate from scroll_bar.py #837

Open
wants to merge 1 commit into
base: PyQt6
Choose a base branch
from

Conversation

apooreapo
Copy link

Default behaviour of scrollable widgets in PyQt and Qt is to propagate the scrolling event to parent widgets whenever their scrolling area is at its end. All of the widgets that use SmoothScrollDelegate would cause an issue when used inside another QScrollArea. By checking if the scrollbar is at its end, we can avoid this issue.

Default behaviour of scrollable widgets in PyQt and Qt is to propagate the scrolling event to parent widgets whenever their scrolling area is at its end. All of the widgets that used SmoothScrollDelegate would cause an issue when used inside another QScrollArea. By checking if the scrollbar is at its end, we can avoid this issue.
@zhiyiYo
Copy link
Owner

zhiyiYo commented May 12, 2024

A more concise way:

def eventFilter(self, obj, e: QEvent):
        if e.type() == QEvent.Type.Wheel:
            # Check if the vertical scroll is at its limit
            verticalAtEnd = (e.angleDelta().y() < 0 and self.vScrollBar.value() == self.vScrollBar.maximum()) or \
                            (e.angleDelta().y() > 0 and self.vScrollBar.value() == self.vScrollBar.minimum())

            # Check if the horizontal scroll is at its limit
            horizontalAtEnd = (e.angleDelta().x() < 0 and self.hScrollBar.value() == self.hScrollBar.maximum()) or \
                              (e.angleDelta().x() > 0 and self.hScrollBar.value() == self.hScrollBar.minimum())

            if verticalAtEnd or horizontalAtEnd:
                return False

            if e.angleDelta().y() != 0:
                if not self.useAni:
                    self.verticalSmoothScroll.wheelEvent(e)
                else:
                    self.vScrollBar.scrollValue(-e.angleDelta().y())
            else:
                if not self.useAni:
                    self.horizonSmoothScroll.wheelEvent(e)
                else:
                    self.hScrollBar.scrollValue(-e.angleDelta().x())

            e.setAccepted(True)
            return True

        return super().eventFilter(obj, e)

Copy link
Owner

@zhiyiYo zhiyiYo left a comment

Choose a reason for hiding this comment

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

We can make the code more concise

@apooreapo apooreapo closed this May 12, 2024
@apooreapo apooreapo reopened this May 12, 2024
@apooreapo
Copy link
Author

Seems good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants