Closed Dima-369 closed 2 years ago
scroll_up_page is implement by scroll_wheel that emulatescroll_up is implemented by the scroll_wheel function. The principle of implementation is to simulate the operation of the mouse wheel to support all pages. The original JavaScript scrolling method cannot adapt to all pages.
If you want to scroll smoothly, you need to introduce a smooth function in the scroll_wheel action. Currently, the scrolling of the EAF browser is not affected by the property QWebEngineSettings.ScrollAnimatorEnabled.
I see. So I tried with this code (I originally used this in qutebrowser
for smooth scroll):
@interactive
def scroll_up_page(self):
''' Scroll page up.'''
self.eval_js("window.scrollBy({top: 300, left: 0, behavior: 'smooth'})")
@interactive(insert_or_do=True)
def scroll_down_page(self):
''' Scroll down a page.'''
self.eval_js("window.scrollBy({top: -300, left: 0, behavior: 'smooth'})")
It does work when self.settings.setAttribute(QWebEngineSettings.ScrollAnimatorEnabled, True)
is added.
But I find it rather sluggish, especially when I hold down the key to scroll large chunks of a page. Do you have any idea how to speed it up?
Smooth scroll will slow down when you hold down the key, it need you implement scroll function that control y offset yourself, eval_js is slow.
Okay, I was hoping that it would be as smooth as in Firefox, but that is apparently not the case.
Closing this, as the smooth scroll code from above works and the sluggishness is not that bad.
@Dima-369 Hi bro, I just use postEvent instead sendEvent in newest version, can you upgrade EAF and test again?
sendEvent will blocking event and wait for the event to be executed to complete, and postEvent just send event to Qt event loop, won't block event loop.
Your problem perhaps fix upgrade EAF. ;)
I would love to try it out, but apparently I have a problem with the current master
on PyQt6: https://github.com/emacs-eaf/emacs-application-framework/issues/967
@manateelazycat Hey, I updated to the latest version, but I noticed how the code in https://github.com/emacs-eaf/emacs-application-framework/issues/960#issuecomment-1108611065 does not result in smooth scroll anymore on Qt6? Can you confirm?
Even with QWebEngineSettings.ScrollAnimatorEnabled
enabled, there is no smooth scroll.
I figured it out!
With Qt 6 on the latest master
, one needs to use self.settings.setAttribute(QWebEngineSettings.WebAttribute.ScrollAnimatorEnabled, True)
(with .WebAttribute
added) to have smooth scroll plus the eval_js
calls as outlined above.
I just use postEvent instead sendEvent in newest version, can you upgrade EAF and test again?
I can confirm that it behaves a lot nicer now! Perfect, thanks!
With Qt 6 on the latest master, one needs to use self.settings.setAttribute(QWebEngineSettings.WebAttribute.ScrollAnimatorEnabled, True) (with .WebAttribute added) to have smooth scroll plus the eval_js calls as outlined above.
Actually, the eval_js
calls are no longer necessary, since the setting seems to apply 'globally' since it applies to all self.scroll_wheel()
calls. Amazing!
I tried this in
core/webengine.py
, but it does not seem to do anything?Or is this only an macOS issue? Does it work for someone else?
I want
eaf-py-proxy-scroll_up_page
to have smooth scroll (similar to how Firefox does it), as right now it just jumps around the page.