PyQt6 WebEngineView - Windows 10 虚拟键盘问题

PyQt6 WebEngineView - Windows 10 virtual keyboard issue

提问人:Haroshow 提问时间:8/14/2023 最后编辑:eyllanescHaroshow 更新时间:8/15/2023 访问量:39

问:

在pyqt6 QWebEngineView中,我在Windows 10(输入:触摸屏,不带键盘)上加载一个url(例如:w3schools模式

我的问题是,当用户打开一个模式(如链接中)时,如果它有一个输入字段,Windows 10 虚拟键盘就会正确显示。当用户触摸“关闭”图标(在虚拟键盘上)时,键盘会正常消失。但是当用户再次触摸屏幕时,虚拟键盘会再次显示,但没有输入字段。

我尝试过捕捉诸如集中注意力,toucing之类的事件,但无济于事。

GIF


from PyQt6.QtCore import QUrl, Qt

from PyQt6.QtWebEngineCore import QWebEngineProfile, QWebEngineSettings, QWebEnginePage
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWidgets import QApplication

import sys
import ctypes

base_url = "https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal"
version = "1.10"


class SWindow(QWebEngineView):
    def __init__(self, windows, parent=None):
        super(SWindow, self).__init__(parent)
        self.myPage = SPage(self)
        self.setPage(self.myPage)
        self._windows = windows
        self._windows.append(self)
        self.setAttribute(Qt.WidgetAttribute.WA_AcceptTouchEvents, True)


        profile = QWebEngineProfile.defaultProfile()
        profile.setPersistentCookiesPolicy(QWebEngineProfile.PersistentCookiesPolicy.ForcePersistentCookies)

        settings = profile.settings()
        settings.setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanOpenWindows, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.LocalStorageEnabled, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.LocalContentCanAccessRemoteUrls, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.LocalContentCanAccessFileUrls, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, True)
        settings.setAttribute(QWebEngineSettings.WebAttribute.AllowRunningInsecureContent, True)

        self.load(QUrl.fromUserInput(base_url))
        self.showMaximized()


class SPage(QWebEnginePage):
    def triggerAction(self, action, checked=False):
        if action == QWebEnginePage.WebAction.OpenLinkInNewWindow:
            self.createWindow(QWebEnginePage.WebAction.WebBrowserWindow)
        return super(SPage, self).triggerAction(action, checked)



if __name__ == "__main__":
    ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('test.desktop.app')
    app = QApplication(sys.argv)
    app.setAttribute(Qt.ApplicationAttribute.AA_SynthesizeMouseForUnhandledTouchEvents, True)
    app.setAttribute(Qt.ApplicationAttribute.AA_SynthesizeMouseForUnhandledTabletEvents, True)

    windows = []
    window = SWindow(windows)

    window.show()

    sys.exit(app.exec())
python pyqt6 虚拟键盘 qwebengineview

评论

0赞 musicamante 8/15/2023
“没有输入字段”是什么意思?你是如何尝试获得这些事件的?请提供一个最小的可重复示例

答: 暂无答案