pywebview icon indicating copy to clipboard operation
pywebview copied to clipboard

PySide6 backend not working

Open AVK636 opened this issue 2 years ago • 8 comments

Installing pywebview with the PySide6 backend like that

pip3 install pywebview[pyside6]

leads to the following error when launching a window:

  File "C:\Users\myuser\Miniconda3\envs\myenv\lib\site-packages\webview\platforms\qt.py", line 323, in __init__
    center = QApplication.desktop().availableGeometry().center() - self.rect().center()
AttributeError: type object 'PySide6.QtWidgets.QApplication' has no attribute 'desktop'

AVK636 avatar Jul 09 '22 00:07 AVK636

@AVK636 I've had to make the following changes to get PySide6 to work. I haven't tried PyQt6 yet.

from qtpy import PYQT6, PYSIDE6

#1 
def contextMenuEvent(self, event):
    if PYSIDE6:
        menu = self.createStandardContextMenu()
    else:
        menu = self.page().createStandardContextMenu()

#2 
if PYSIDE6:
    center = QScreen.availableGeometry(QApplication.primaryScreen()).center() - self.rect().center()
    self.move(center.x(), center.y() - 16)
else:
    center = QApplication.desktop().availableGeometry().center() - self.rect().center()
    self.move(center.x(), center.y())

#3 def on_evaluate_js
try:    # < Qt5.6
    if PYSIDE6:
        self.view.page().runJavaScript(script, 0, return_result)
    else:
        self.view.page().runJavaScript(script, return_result)

Sorry if this is kind of messy. I'm on my way to the airport.

sbbosco avatar Jul 09 '22 12:07 sbbosco

Thanks, with those changes it works for me as well. However, I observed strange behaviour regarding the browser cache, cookies, etc. With PySide6, the webview doesn't seem to save any cached data or cookies. With PyQt5 on Windows, the webview created a pywebview dir in my local app data dir. Using PySide6, this is not the case. Any ideas on that?

AVK636 avatar Jul 11 '22 00:07 AVK636

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 10 '22 02:08 github-actions[bot]

@AVK636 This code seems to enable disk cache for PySide6.

    class WebPage(QWebPage):
        def __init__(self, parent=None):
            qprofile = QWebEngineProfile('diskcache') if PYSIDE6 else None
            super(BrowserView.WebPage, self).__init__(qprofile, parent)
            print(self.profile().httpCacheType())
            print(self.profile().cachePath())
            print(self.profile().persistentCookiesPolicy())

You will need to add QWebEngineProfile to the import statement

sbbosco avatar Aug 10 '22 21:08 sbbosco

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 10 '22 04:09 github-actions[bot]

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.

github-actions[bot] avatar Sep 15 '22 04:09 github-actions[bot]

@sbbosco Care to create a PR?

r0x0r avatar Sep 16 '22 11:09 r0x0r

@r0x0r I'll try to work on this in the next few weeks. Thanks!

sbbosco avatar Sep 17 '22 14:09 sbbosco

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Oct 18 '22 04:10 github-actions[bot]

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.

github-actions[bot] avatar Oct 24 '22 04:10 github-actions[bot]