本文整理汇总了Python中PyQt5.QtWidgets.QTextBrowser.verticalScrollBar方法的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser.verticalScrollBar方法的具体用法?Python QTextBrowser.verticalScrollBar怎么用?Python QTextBrowser.verticalScrollBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTextBrowser
的用法示例。
在下文中一共展示了QTextBrowser.verticalScrollBar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QChatWidget
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import verticalScrollBar [as 别名]
#.........这里部分代码省略.........
self.addNickButton.setGeometry(584, 8, 31, 23)
self.addNickButton.clicked.connect(self.addNickScreen)
self.addNickButton.show()
def addUser(self, user):
nick = str(user.text()).lower()
# Validate the given nick
nickStatus = utils.isValidNick(nick)
if nickStatus == errors.VALID_NICK:
# TODO: Group chats
pass
elif nickStatus == errors.INVALID_NICK_CONTENT:
QMessageBox.warning(self, errors.TITLE_INVALID_NICK, errors.INVALID_NICK_CONTENT)
elif nickStatus == errors.INVALID_NICK_LENGTH:
QMessageBox.warning(self, errors.TITLE_INVALID_NICK, errors.INVALID_NICK_LENGTH)
elif nickStatus == errors.INVALID_EMPTY_NICK:
QMessageBox.warning(self, errors.TITLE_EMPTY_NICK, errors.EMPTY_NICK)
def addNickScreen(self):
self.chat_log.setEnabled(False)
self.chat_input.setEnabled(False)
self.send_button.setEnabled(False)
self.addNickButton.hide()
self.addUserText = QLabel("Enter a username to add a user to the group chat.", self)
self.addUserText.setGeometry(200, 20, 300, 100)
self.addUserText.show()
self.user = QLineEdit(self)
self.user.setGeometry(200, 120, 240, 20)
self.user.returnPressed.connect(self.addUser)
self.user.show()
self.addUserButton = QPushButton('Add User', self)
self.addUserButton.setGeometry(250, 150, 150, 25)
self.addUserButton.clicked.connect(lambda: self.addUser(self.user))
self.addUserButton.show()
self.cancel = QPushButton('Cancel', self)
self.cancel.setGeometry(298, 210, 51, 23)
self.cancel.clicked.connect(lambda: self.chat_log.setEnabled(True))
self.cancel.clicked.connect(lambda: self.chat_input.setEnabled(True))
self.cancel.clicked.connect(lambda: self.send_button.setEnabled(True))
self.cancel.clicked.connect(self.addUserText.hide)
self.cancel.clicked.connect(self.user.hide)
self.cancel.clicked.connect(self.addUserButton.hide)
self.cancel.clicked.connect(self.addNickButton.show)
self.cancel.clicked.connect(self.cancel.hide)
self.cancel.show()
def appendMessage(self, message, source, show_timestamp_and_nick=True):
color = self.__getColor(source)
if show_timestamp_and_nick:
timestamp = '<font color="' + color + '">(' + getTimestamp() + ') <strong>' + \
(self.chat_window.client.nick if source == MSG_SENDER else self.nick) + \
':</strong></font> '
else:
timestamp = ''
# If the user has scrolled up (current value != maximum), do not move the scrollbar
# to the bottom after appending the message
shouldScroll = True
scrollbar = self.chat_log.verticalScrollBar()
if scrollbar.value() != scrollbar.maximum() and source != constants.SENDER:
shouldScroll = False
self.chat_log.append(timestamp + message)
# Move the vertical scrollbar to the bottom of the chat log
if shouldScroll:
scrollbar.setValue(scrollbar.maximum())
def __linkify(self, text):
matches = self.url_regex.findall(text)
for match in matches:
text = text.replace(match[0], '<a href="%s">%s</a>' % (match[0], match[0]))
return text
def __getColor(self, source):
if source == MSG_SENDER:
if qtUtils.is_light_theme:
return '#0000CC'
else:
return '#6666FF'
elif source == MSG_RECEIVER:
if qtUtils.is_light_theme:
return '#CC0000'
else:
return '#CC3333'
else:
if qtUtils.is_light_theme:
return '#000000'
else:
return '#FFFFFF'
def disable(self):
self.disabled = True
self.chat_input.setReadOnly(True)
def enable(self):
self.disabled = False
self.chat_input.setReadOnly(False)