QClipboard::dataChanged() was not emitted in QtWebEngine context

Zhao Lee redstone-cold at 163.com
Sat Mar 19 12:08:58 GMT 2022


QClipboard::dataChanged() was not emitted in QtWebEngine context with pyqt6 or pyside6, but it works fine with qt5/pyqt5, how to solve it ? Environment:

Python: 3.9.10 (tags/v3.9.10:f2f3f53, Jan 172022, 15:14:21) [MSC v.192964bit (AMD64)]
Flavor: Unknown
Executable: C:\Users\Oscar\AppData\Local\Programs\Python\Python39\python.exe
OS: Windows
Arch: x86_64
WindowsRelease: 10

>>> from PyQt6.QtCore import *
>>> QT_VERSION_STR
'6.2.3'
>>> PYQT_VERSION_STR
'6.2.3'
>>> 

from PyQt6.QtCore import *
from PyQt6.QtCore import pyqtSlot as Slot
from PyQt6.QtCore import pyqtSignal as Signal
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from PyQt6.QtWebEngineWidgets import *
from PyQt6.QtWebEngineCore import *
import sys


classWebEngineView(QWebEngineView):  #

    def __init__(self, parent=None):
        super().__init__(parent)
        self.page().settings().setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True)
        self.load(QUrl('https://doc.qt.io/qt-6/qwebenginesettings.html'))
        self.clipboard = QGuiApplication.clipboard()
        self.clipboard.dataChanged.connect(self.clipboardTextChanged)

    @Slot()
    def clipboardTextChanged(self):
        self.copiedText = self.clipboard.text()

        print(self.sender(), self.copiedText)


if __name__ == "__main__":

    app = QApplication(sys.argv)
    webEngineView = WebEngineView()
    webEngineView.show()
    sys.exit(app.exec())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220319/25c1075d/attachment.htm>


More information about the PyQt mailing list