0

I am trying to build a kiosk browser applet, which has two elements. A keyboard view and a normal webengine browser window. I would like to link an event, where the browser requests a keyboard to pop up. Eg. when an input is clicked/pressed. So I can show the keyboard view. Also hide it when it is no longer needed.

Does the QWebEngine have a function/connect which I can use to open the keyboard. As a last result it can be a script run by the browser where it injects an eventlistener to all input elements, but this is rather mundane and can easily break with different inputs/input types and on different pages.

It would be better if it is done in Python so I doesn't have to inject a script every time.

Below you have the basic app for the "Kiosk", no other features just a browser and another browser (to mimic the keyboard)

import sys
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from PySide6.QtWebEngineWidgets import *


class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()

        self.setWindowTitle("Keyboard Wrapper")
        self.setWindowIcon(QIcon("icon.png"))

        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl("https://www.google.com"))

        self.browser.loadFinished.connect(self.update_title)

        self.nav_bar = QToolBar()
        self.addToolBar(self.nav_bar)

        back_btn = QAction("Back", self)
        back_btn.triggered.connect(self.browser.back)
        self.nav_bar.addAction(back_btn)

        forward_btn = QAction("Forward", self)
        forward_btn.triggered.connect(self.browser.forward)
        self.nav_bar.addAction(forward_btn)

        reload_btn = QAction("Reload", self)
        reload_btn.triggered.connect(self.browser.reload)
        self.nav_bar.addAction(reload_btn)

        home_btn = QAction("Home", self)
        home_btn.triggered.connect(self.navigate_home)
        self.nav_bar.addAction(home_btn)

        self.url_bar = QLineEdit()
        self.url_bar.returnPressed.connect(self.navigate_to_url)
        self.nav_bar.addWidget(self.url_bar)

        self.browser.urlChanged.connect(self.update_url)

        self.keyboard_container = QWebEngineView()
        self.keyboard_container.setUrl(
            QUrl("https://example.com/keyboard"))

        self.setCentralWidget(self.browser)

        self.keyboard_container.page().setBackgroundColor(Qt.transparent)
        self.keyboard_container.setAttribute(Qt.WA_TranslucentBackground)
        self.keyboard_container.setWindowFlags(Qt.FramelessWindowHint)
        x = 0
        y = 1080 - (1080 * 0.3) - 60
        self.keyboard_container.setGeometry(x, y, 1920, 325)
        self.keyboard_container.setWindowFlag(Qt.WindowStaysOnTopHint)

        self.showMaximized()
        self.browser.showFullScreen()

    def show_keyboard(self):
        self.keyboard_container.show()

    def hide_keyboard(self):
        self.keyboard_container.hide()

    def navigate_home(self):
        self.browser.setUrl(QUrl("https://www.google.com"))

    def navigate_to_url(self):
        url = self.url_bar.text()
        self.browser.setUrl(QUrl(url))

    def update_url(self, q):
        self.url_bar.setText(q.toString())

    def update_title(self):
        title = self.browser.page().title()
        self.setWindowTitle(title)


app = QApplication(sys.argv)
QApplication.setApplicationName("Keyboard Wrapper")
window = MainWindow()
app.exec_()
aberst
  • 47
  • 5
  • There's no public API for a custom input method. So your best bet will be either implementing it with Javascript or using the [Qt Virtual Keyboard](https://doc.qt.io/qt-6/qtvirtualkeyboard-index.html) and QML ```WebEngineView``` with ```InputPanel```. – relent95 Mar 22 '23 at 05:49

0 Answers0