Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ffa7d8b

Browse files
committed
Update
1 parent 18f2a3e commit ffa7d8b

24 files changed

+1866
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QMainWindow, QTextBrowser
4+
from PyQt5.QtGui import QFont
5+
6+
7+
class Form(QMainWindow):
8+
def __init__(self):
9+
super().__init__()
10+
self.init_ui()
11+
12+
def init_ui(self):
13+
self.resize(400, 300)
14+
self.setWindowTitle("QTextBrowser")
15+
text_browser = QTextBrowser()
16+
text_browser.setOpenExternalLinks(True)
17+
text_browser.setFont(QFont("Segue UI", 20))
18+
text_browser.append("Some text")
19+
text_browser.append("<a href=https://qt.io>Qt</a>")
20+
self.setCentralWidget(text_browser)
21+
self.show()
22+
23+
24+
app = QApplication(sys.argv)
25+
form = Form()
26+
sys.exit(app.exec_())
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QApplication, QMainWindow, QTextBrowser
4+
5+
6+
class Form(QMainWindow):
7+
def __init__(self):
8+
"""MainWindow constructor."""
9+
super().__init__()
10+
# Main UI code goes here
11+
main = QTextBrowser()
12+
self.setCentralWidget(main)
13+
14+
# Must come before the HTML is inserted
15+
main.document().setDefaultStyleSheet(
16+
"body {color: #333; font-size: 14px;} "
17+
"h2 {background: #CCF; color: #443;} "
18+
"h1 {background: #001133; color: white;} "
19+
)
20+
21+
# TextBrowser background is a widget style, not a document style
22+
main.setStyleSheet("background-color: #EEF;")
23+
with open("htmls\\new.html", "r") as fh:
24+
main.insertHtml(fh.read())
25+
26+
main.setOpenExternalLinks(True)
27+
28+
# End main UI code
29+
self.show()
30+
31+
32+
app = QApplication(sys.argv)
33+
form = Form()
34+
sys.exit(app.exec_())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /