当前位置: 首页>>代码示例>>Python>>正文


Python QTextBrowser.document方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QTextBrowser.document方法的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser.document方法的具体用法?Python QTextBrowser.document怎么用?Python QTextBrowser.document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QTextBrowser的用法示例。


在下文中一共展示了QTextBrowser.document方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SourceViewer

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import document [as 别名]
class SourceViewer(QDialog):
    def __init__(self, browser):
        super(SourceViewer, self).__init__(browser.parentWidget())

        layout = QVBoxLayout()
        layout.setContentsMargins(4, 4, 4, 4)
        self.setLayout(layout)
        
        self.urlLabel = QLabel(wordWrap=True)
        layout.addWidget(self.urlLabel)
        self.textbrowser = QTextBrowser()
        layout.addWidget(self.textbrowser)
        
        self.urlLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.textbrowser.setLineWrapMode(QTextBrowser.NoWrap)
        
        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
        app.translateUI(self)
        qutil.saveDialogSize(self, "helpbrowser/sourceviewer/size", QSize(400, 300))
        
    def translateUI(self):
        self.setWindowTitle(app.caption(_("LilyPond Source")))
        
    def readSettings(self):
        data = textformats.formatData('editor')
        self.textbrowser.setPalette(data.palette())
        self.textbrowser.setFont(data.font)
        highlighter.highlight(self.textbrowser.document())
        
    def showReply(self, reply):
        reply.setParent(self)
        self.urlLabel.setText(reply.url().toString())
        self._reply = reply
        reply.finished.connect(self.loadingFinished)
        self.textbrowser.clear()
        self.show()
        
    def loadingFinished(self):
        data = self._reply.readAll()
        self._reply.close()
        self._reply.deleteLater()
        del self._reply
        self.textbrowser.clear()
        self.textbrowser.setText(str(data, 'utf-8', 'replace'))
        highlighter.highlight(self.textbrowser.document())
开发者ID:AlexSchr,项目名称:frescobaldi,代码行数:48,代码来源:sourceviewer.py

示例2: add_text

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import document [as 别名]
    def add_text(self):
        self.process_text()
        text = QTextBrowser()
        text.setHtml(self.text)
        text.setOpenLinks(False)
        # text.moveCursor(QTextCursor.End)
        text.setMinimumWidth(500)
        text.setMaximumWidth(500)
        text.document().setTextWidth(500)
        text.setMinimumHeight((text.document().size().height())+5)
        text.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)

        text.anchorClicked.connect(self.link_clicked)

        self.lay.addWidget(text, 1, 1, 1, 3)
开发者ID:grsakea,项目名称:pyt,代码行数:17,代码来源:gtweet.py

示例3: Browser

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import document [as 别名]
class Browser(QWidget):
	def __init__(self,parent_,url,cname,fname):
		super(Browser,self).__init__(parent_)
		self.parent_=parent_
		self.initUI(url,cname,fname)

	def initUI(self,url,cname,fname):
		lbl = QLabel()
		lbl.setText('Forum News - '+cname)
		lbl.setObjectName('hlbl')
		self.browser = QTextBrowser()
		self.browser.document().setDefaultStyleSheet('p{font-size:12px;} div{margin-left:20px;}')

		f = open(url,'r')
		ftext = '<div><br><h3><b>%s</b></h3>'%fname + str(f.read())+'<br></div>'
		self.browser.setHtml(ftext)
		self.browser.setFrameStyle(QFrame.NoFrame)

		self.backBtn = QPushButton(QIcon(':/Assets/close2.png'),'Close')
		self.backBtn.setObjectName('backBtn')
		self.backBtn.clicked.connect(partial(self.parent_.closeTextBrowser))
		frame = topFrame(self.backBtn,lbl)
		frame.setObjectName('nFrameEven')


		self.widget = QWidget(self)
		self.vbox = QVBoxLayout()
		self.vbox.setSpacing(3)
		self.vbox.addWidget(frame)
		self.vbox.addWidget(self.browser)

		self.vbox.setContentsMargins(0,0,0,0)
		self.widget.setLayout(self.vbox)
		self.scroll = QScrollArea(self)
		self.scroll.setWidget(self.widget)
		self.scroll.setWidgetResizable(True)
		self.scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
		self.scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

		vbox1 = QVBoxLayout()
		vbox1.setContentsMargins(0,0,0,0)
		vbox1.setSpacing(0)

		vbox1.addWidget(self.scroll)
		self.setLayout(vbox1)
开发者ID:AkshayAgarwal007,项目名称:Moodly,代码行数:47,代码来源:view.py

示例4: AboutWhat

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import document [as 别名]
class AboutWhat(QDialog):

    def __init__(self, parent=None, pytesting=False):
        super(AboutWhat, self).__init__(parent)
        self._pytesting = pytesting
        self.setWindowTitle('About %s' % __appname__)
        self.setWindowIcon(icons.get_icon('master'))
        self.setMinimumSize(800, 700)
        self.setWindowFlags(Qt.Window |
                            Qt.CustomizeWindowHint |
                            Qt.WindowCloseButtonHint)

        self.__initUI__()

    def __initUI__(self):
        """Initialize the GUI."""
        self.manager_updates = None

        # ---- AboutTextBox

        self.AboutTextBox = QTextBrowser()
        self.AboutTextBox.installEventFilter(self)
        self.AboutTextBox.setReadOnly(True)
        self.AboutTextBox.setFixedWidth(850)
        self.AboutTextBox.setFrameStyle(0)
        self.AboutTextBox.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.AboutTextBox.setOpenExternalLinks(True)

        self.AboutTextBox.setStyleSheet('QTextEdit {background-color:"white"}')
        self.AboutTextBox.document().setDocumentMargin(0)
        self.set_html_in_AboutTextBox()

        # ---- toolbar

        self.ok_btn = QPushButton('OK')
        self.ok_btn.clicked.connect(self.close)

        self.btn_check_updates = QPushButton(' Check for Updates ')
        self.btn_check_updates.clicked.connect(
                self._btn_check_updates_isclicked)

        toolbar = QGridLayout()
        toolbar.addWidget(self.btn_check_updates, 0, 1)
        toolbar.addWidget(self.ok_btn, 0, 2)
        toolbar.setContentsMargins(0, 0, 0, 0)
        toolbar.setColumnStretch(0, 100)

        # ---- Main Grid

        grid = QGridLayout()
        grid.setSpacing(10)

        grid.addWidget(self.AboutTextBox, 0, 1)
        grid.addLayout(toolbar, 1, 1)

        grid.setColumnStretch(1, 500)
        grid.setContentsMargins(10, 10, 10, 10)

        self.setLayout(grid)
        self.ok_btn.setFocus()

    @QSlot()
    def _btn_check_updates_isclicked(self):
        """Handles when the button to check for updates is clicked."""
        self.manager_updates = ManagerUpdates(self, self._pytesting)

    def set_html_in_AboutTextBox(self):
        """Set the text in the About GWHAT text browser widget."""

        # ---- Header logo

        width = 750
        filename = os.path.join(
                __rootdir__, 'ressources', 'WHAT_banner_750px.png')

        # http://doc.qt.io/qt-4.8/richtext-html-subset.html

        if platform.system() == 'Windows':
            fontfamily = "Segoe UI"  # "Cambria" #"Calibri" #"Segoe UI""
        elif platform.system() == 'Linux':
            fontfamily = "Ubuntu"

        html = """
               <html>
               <head>
               <style>
               p {font-size: 16px;
                  font-family: "%s";
                  margin-right:50px;
                  margin-left:50px;
                  }
               p1 {font-size: 16px;
                   font-family: "%s";
                   margin-right:50px;
                   margin-left:50px;
                   }
               </style>
               </head>
               <body>
               """ % (fontfamily, fontfamily)
#.........这里部分代码省略.........
开发者ID:jnsebgosselin,项目名称:WHAT,代码行数:103,代码来源:about.py

示例5: Widget

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import document [as 别名]
class Widget(QWidget):
    def __init__(self, panel):
        super(Widget, self).__init__(panel)
        
        layout = QVBoxLayout()
        self.setLayout(layout)
        layout.setSpacing(0)
        
        self.searchEntry = SearchLineEdit()
        self.treeView = QTreeView(contextMenuPolicy=Qt.CustomContextMenu)
        self.textView = QTextBrowser()
        
        applyButton = QToolButton(autoRaise=True)
        editButton = QToolButton(autoRaise=True)
        addButton = QToolButton(autoRaise=True)
        self.menuButton = QPushButton(flat=True)
        menu = QMenu(self.menuButton)
        self.menuButton.setMenu(menu)
        
        splitter = QSplitter(Qt.Vertical)
        top = QHBoxLayout()
        layout.addLayout(top)
        splitter.addWidget(self.treeView)
        splitter.addWidget(self.textView)
        layout.addWidget(splitter)
        splitter.setSizes([200, 100])
        splitter.setCollapsible(0, False)
        
        top.addWidget(self.searchEntry)
        top.addWidget(applyButton)
        top.addSpacing(10)
        top.addWidget(addButton)
        top.addWidget(editButton)
        top.addWidget(self.menuButton)
        
        # action generator for actions added to search entry
        def act(slot, icon=None):
            a = QAction(self, triggered=slot)
            self.addAction(a)
            a.setShortcutContext(Qt.WidgetWithChildrenShortcut)
            icon and a.setIcon(icons.get(icon))
            return a
        
        # hide if ESC pressed in lineedit
        a = act(self.slotEscapePressed)
        a.setShortcut(QKeySequence(Qt.Key_Escape))
        
        # import action
        a = self.importAction = act(self.slotImport, 'document-open')
        menu.addAction(a)
        
        # export action
        a = self.exportAction = act(self.slotExport, 'document-save-as')
        menu.addAction(a)
        
        # apply button
        a = self.applyAction = act(self.slotApply, 'edit-paste')
        applyButton.setDefaultAction(a)
        menu.addSeparator()
        menu.addAction(a)
        
        # add button
        a = self.addAction_ = act(self.slotAdd, 'list-add')
        a.setShortcut(QKeySequence(Qt.Key_Insert))
        addButton.setDefaultAction(a)
        menu.addSeparator()
        menu.addAction(a)
        
        # edit button
        a = self.editAction = act(self.slotEdit, 'document-edit')
        a.setShortcut(QKeySequence(Qt.Key_F2))
        editButton.setDefaultAction(a)
        menu.addAction(a)
        
        # set shortcut action
        a = self.shortcutAction = act(self.slotShortcut, 'preferences-desktop-keyboard-shortcuts')
        menu.addAction(a)
        
        # delete action
        a = self.deleteAction = act(self.slotDelete, 'list-remove')
        a.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Delete))
        menu.addAction(a)
        
        # restore action
        a = self.restoreAction = act(self.slotRestore)
        menu.addSeparator()
        menu.addAction(a)
        
        # help button
        a = self.helpAction = act(self.slotHelp, 'help-contents')
        menu.addSeparator()
        menu.addAction(a)
        
        self.treeView.setSelectionBehavior(QTreeView.SelectRows)
        self.treeView.setSelectionMode(QTreeView.ExtendedSelection)
        self.treeView.setRootIsDecorated(False)
        self.treeView.setAllColumnsShowFocus(True)
        self.treeView.setModel(model.model())
        self.treeView.setCurrentIndex(QModelIndex())
        
#.........这里部分代码省略.........
开发者ID:AlexSchr,项目名称:frescobaldi,代码行数:103,代码来源:widget.py


注:本文中的PyQt5.QtWidgets.QTextBrowser.document方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。