pywebview
pywebview copied to clipboard
PySide6 backend not working
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 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.
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?
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.
@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
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.
The message to post on the issue when closing it. If none provided, will not comment when closing an issue.
@sbbosco Care to create a PR?
@r0x0r I'll try to work on this in the next few weeks. Thanks!
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.
The message to post on the issue when closing it. If none provided, will not comment when closing an issue.