本文整理汇总了Python中PyQt5.QtWidgets.QTextBrowser.setFocusPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser.setFocusPolicy方法的具体用法?Python QTextBrowser.setFocusPolicy怎么用?Python QTextBrowser.setFocusPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTextBrowser
的用法示例。
在下文中一共展示了QTextBrowser.setFocusPolicy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PreviewWidgetColor
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setFocusPolicy [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)
示例2: PreviewWidgetColor
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setFocusPolicy [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)