0

I am using Python 3.9 and PyQt5 and I am trying to display an input html tag in a QTextBrowser widget. When I try to add an input tag the html page looks blank when I view it in the QTextBrowser. Is there any way that I could add an input tag to the QTextBrowser? This is what my HTML code looks like.

<html>
<body>
<input type="text"></input>
</body>
</html>

1 Answer 1

1

Unfortunately QTextBrowser only handles a limited subset of HTML4 elements and among them there is no input.

One possible solution is to use QWebEngineView:

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView

html = """
<!DOCTYPE html>
<html>
<body>
<h1>The input element</h1>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</body>
</html>
"""


def main():
    app = QApplication(sys.argv)

    view = QWebEngineView()
    view.setHtml(html)
    view.resize(640, 480)
    view.show()

    sys.exit(app.exec_())


if __name__ == "__main__":
    main()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.