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


Python QTextBrowser.installEventFilter方法代码示例

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


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

示例1: PreviewWidgetColor

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import installEventFilter [as 别名]
class PreviewWidgetColor(QGroupBox):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setTitle(self.tr("Preview"))
        self.setMaximumHeight(120)
        self.parent = parent

        vboxLayout = QVBoxLayout(self)
        self.previewGroupBox = QGroupBox(self)
        self.previewGroupBox.setObjectName("previewGroupBox")
        vboxLayout.addWidget(self.previewGroupBox)

        self.horizontalLayout = QHBoxLayout(self.previewGroupBox)
        self.verticalLayout = QVBoxLayout()
        self.horizontalLayout.addLayout(self.verticalLayout)

        self.previewLabel = QLabel(self.previewGroupBox)
        self.previewLabel.setText(self.tr("Window Text"))
        self.previewLabel.setObjectName("previewLabel")
        self.verticalLayout.addWidget(self.previewLabel)

        self.previewPushButton = QPushButton(self.previewGroupBox)
        self.previewPushButton.setText(self.tr("Button"))
        self.previewPushButton.setObjectName("previewPushButton")
        self.verticalLayout.addWidget(self.previewPushButton)

        self.previewTextBrowser = QTextBrowser(self.previewGroupBox)
        self.previewTextBrowser.setObjectName("previewTextBrowser")

        css = iniToCss(os.path.join("/usr/share/color-schemes", self.parent.children()[1].currentItem().colorSchemeName))

        self.previewTextBrowser.setHtml("""<style>#unclicked {color : rgb(%s);}
        #clicked {color : rgb(%s);}</style>"""%(css[1][0],css[1][1]) +
        self.tr("""<p>Normal text <a id='unclicked' href='#'>link</a> <a id='clicked' href='#'>visited</a></p>"""))


        self.horizontalLayout.addWidget(self.previewTextBrowser)


        self.previewPushButton.installEventFilter(self.previewGroupBox)
        self.previewPushButton.setFocusPolicy(Qt.NoFocus)

        self.previewTextBrowser.installEventFilter(self.previewGroupBox)
        self.previewTextBrowser.setFocusPolicy(Qt.NoFocus)
        self.previewTextBrowser.setTextInteractionFlags(Qt.NoTextInteraction)

    def eventFilter(self, obj, event):
        if self.previewPushButton:
            if event.type() == QEvent.MouseButtonRelease:
                return True
            elif event.type() == QEvent.MouseButtonPress:
                return True
            elif event.type() == QEvent.MouseButtonDblClick:
                return True

            else:
                return False
        else:
            super().eventFilter(obj, event)
开发者ID:KaOSx,项目名称:kaptan,代码行数:61,代码来源:tabwidget.py

示例2: AboutWhat

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import installEventFilter [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

示例3: PreviewWidgetColor

# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import installEventFilter [as 别名]
class PreviewWidgetColor(QGroupBox):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setTitle(self.tr("Preview"))
        self.setMaximumHeight(120)

        vboxLayout = QVBoxLayout(self)
        self.previewGroupBox = QGroupBox(self)
        self.previewGroupBox.setObjectName("previewGroupBox")
        vboxLayout.addWidget(self.previewGroupBox)

        self.horizontalLayout = QHBoxLayout(self.previewGroupBox)
        self.verticalLayout = QVBoxLayout()
        self.horizontalLayout.addLayout(self.verticalLayout)

        self.previewLabel = QLabel(self.previewGroupBox)
        self.previewLabel.setText(self.tr("Window Text"))
        self.previewLabel.setObjectName("previewLabel")
        self.verticalLayout.addWidget(self.previewLabel)

        self.previewPushButton = QPushButton(self.previewGroupBox)
        self.previewPushButton.setText(self.tr("Button"))
        self.previewPushButton.setObjectName("previewPushButton")
        self.verticalLayout.addWidget(self.previewPushButton)

        self.previewTextBrowser = QTextBrowser(self.previewGroupBox)
        self.previewTextBrowser.setObjectName("previewTextBrowser")

        self.previewTextBrowser.insertHtml(self.tr("""<style>
        #unclicked {color : rgb(255,0,0);}
        #sunclicked {color : rgb(255,0,255);}
        #clicked {color : rgb(0,255,0);}
        #sclicked {color : rgb(0,0,255);}
        </style>
        <p>Normal metin <a id='unclicked' href='#'>bağlantı</a> <a id='clicked' href='#'>ziyaret edilmiş</a></p>
        <p>Seçili metin <a id='sunclicked' href='#'>bağlantı</a> <a id='sclicked' href='#'>ziyaret edilmiş</a></p>"""))



        cursor = self.previewTextBrowser.textCursor()
        cursor.setPosition(39)
        cursor.setPosition(76, QTextCursor.KeepAnchor)
        self.previewTextBrowser.setTextCursor(cursor)

        self.horizontalLayout.addWidget(self.previewTextBrowser)


        self.previewPushButton.installEventFilter(self.previewGroupBox)
        self.previewPushButton.setFocusPolicy(Qt.NoFocus)

        self.previewTextBrowser.installEventFilter(self.previewGroupBox)
        self.previewTextBrowser.setFocusPolicy(Qt.NoFocus)
        self.previewTextBrowser.setTextInteractionFlags(Qt.NoTextInteraction)

    def eventFilter(self, obj, event):
        if self.previewPushButton:
            if event.type() == QEvent.MouseButtonRelease:
                return True
            elif event.type() == QEvent.MouseButtonPress:
                return True
            elif event.type() == QEvent.MouseButtonDblClick:
                return True

            else:
                return False
        else:
            super().eventFilter(obj, event)
开发者ID:WhiteSymmetry,项目名称:kaptan,代码行数:69,代码来源:tabwidget.py


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