本文整理汇总了Python中PyQt4.Qt.QTextBrowser.setHtml方法的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser.setHtml方法的具体用法?Python QTextBrowser.setHtml怎么用?Python QTextBrowser.setHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QTextBrowser
的用法示例。
在下文中一共展示了QTextBrowser.setHtml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ViewLog
# 需要导入模块: from PyQt4.Qt import QTextBrowser [as 别名]
# 或者: from PyQt4.Qt.QTextBrowser import setHtml [as 别名]
class ViewLog(QDialog): # {{{
def __init__(self, title, html, parent=None):
QDialog.__init__(self, parent)
self.l = l = QVBoxLayout()
self.setLayout(l)
self.tb = QTextBrowser(self)
self.tb.setHtml('<pre style="font-family: monospace">%s</pre>' % html)
l.addWidget(self.tb)
self.bb = QDialogButtonBox(QDialogButtonBox.Ok)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
self.copy_button = self.bb.addButton(_('Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.copy_button.clicked.connect(self.copy_to_clipboard)
l.addWidget(self.bb)
self.setModal(False)
self.resize(QSize(700, 500))
self.setWindowTitle(title)
self.setWindowIcon(QIcon(I('debug.png')))
self.show()
def copy_to_clipboard(self):
txt = self.tb.toPlainText()
QApplication.clipboard().setText(txt)
示例2: LogViewer
# 需要导入模块: from PyQt4.Qt import QTextBrowser [as 别名]
# 或者: from PyQt4.Qt.QTextBrowser import setHtml [as 别名]
class LogViewer(QDialog): # {{{
def __init__(self, log, parent=None):
QDialog.__init__(self, parent)
self.log = log
self.l = l = QVBoxLayout()
self.setLayout(l)
self.tb = QTextBrowser(self)
l.addWidget(self.tb)
self.bb = QDialogButtonBox(QDialogButtonBox.Close)
l.addWidget(self.bb)
self.copy_button = self.bb.addButton(_('Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.bb.rejected.connect(self.reject)
self.bb.accepted.connect(self.accept)
self.setWindowTitle(_('Download log'))
self.setWindowIcon(QIcon(I('debug.png')))
self.resize(QSize(800, 400))
self.keep_updating = True
self.last_html = None
self.finished.connect(self.stop)
QTimer.singleShot(100, self.update_log)
self.show()
def copy_to_clipboard(self):
QApplication.clipboard().setText(''.join(self.log.plain_text))
def stop(self, *args):
self.keep_updating = False
def update_log(self):
if not self.keep_updating:
return
html = self.log.html
if html != self.last_html:
self.last_html = html
self.tb.setHtml('<pre style="font-family:monospace">%s</pre>'%html)
QTimer.singleShot(1000, self.update_log)
示例3: WikiHelpBrowser
# 需要导入模块: from PyQt4.Qt import QTextBrowser [as 别名]
# 或者: from PyQt4.Qt.QTextBrowser import setHtml [as 别名]
class WikiHelpBrowser(QDialog):
"""
The WikiHelpBrowser Dialog.
"""
def __init__(self, text, parent=None, clicked_func=None, caption="(caption)", size=None):
QDialog.__init__(self, parent)
self.setWindowTitle(caption)
self.setWindowIcon(QtGui.QIcon("ui/border/MainWindow"))
self.setObjectName("WikiHelpBrowser")
TextBrowserLayout = QGridLayout(self)
TextBrowserLayout.setSpacing(5)
TextBrowserLayout.setMargin(2)
self.text_browser = QTextBrowser(self)
self.text_browser.setOpenExternalLinks(True)
self.text_browser.setObjectName("text_browser")
TextBrowserLayout.addWidget(self.text_browser, 0, 0, 1, 0)
self.text_browser.setMinimumSize(400, 200)
# make it pale yellow like a post-it note
self.text_browser.setHtml('<qt bgcolor="#FFFF80">' + text)
self.close_button = QPushButton(self)
self.close_button.setObjectName("close_button")
self.close_button.setText("Close")
TextBrowserLayout.addWidget(self.close_button, 1, 1)
spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
TextBrowserLayout.addItem(spacer, 1, 0)
self.resize(QSize(300, 300).expandedTo(self.minimumSizeHint()))
if size == 1:
self.text_browser.setMinimumSize(200, 400)
self.resize(QSize(300, 550).expandedTo(self.minimumSizeHint()))
if size == 2:
self.resize(QSize(650, 250).expandedTo(self.minimumSizeHint()))
self.connect(self.close_button, SIGNAL("clicked()"), self.close)
return
pass