本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.keyPressEvent方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.keyPressEvent方法的具體用法?Python QLineEdit.keyPressEvent怎麽用?Python QLineEdit.keyPressEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.keyPressEvent方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, event):
if event.key() == Qt.Key_Space:
item = self.frame.listWidget.currentItem()
self.setText(item._data.comparison)
return
QLineEdit.keyPressEvent(self, event)
currentRow = self.frame.listWidget.currentRow()
if event.key() == Qt.Key_Down:
count = self.frame.listWidget.count()
#If the current position is greater than the amount of items in
#the list - 6, then try to fetch more items in the list.
if currentRow >= (count - 6):
locations = self._create_list_widget_items(self.tempLocations)
self.frame.fetch_more(locations)
#While the current position is lower that the list size go to next
if currentRow != count - 1:
self.frame.listWidget.setCurrentRow(
self.frame.listWidget.currentRow() + 1)
elif event.key() == Qt.Key_Up:
#while the current position is greater than 0, go to previous
if currentRow > 0:
self.frame.listWidget.setCurrentRow(
self.frame.listWidget.currentRow() - 1)
elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
#If the user press enter, go to the item selected
item = self.frame.listWidget.currentItem()
self._go_to_location(item)
示例2: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_Up:
self.model.up()
elif key == Qt.Key_Down:
self.model.down()
else:
oldPrefix = self._prefix()
QLineEdit.keyPressEvent(self, event)
prefix = self._prefix()
if len(oldPrefix) < len(prefix):
self.model.text = prefix
示例3: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, e):
if e.key() == Qt.Key_Return and self.lineEditCategory.hasFocus():
if self.radioButtonNew.isChecked():
t = self.lineEditCategory.text()
if t > '' and not self.listWidgetCategories.findItems(t, Qt.MatchExactly):
item = QListWidgetItem(t, self.listWidgetCategories)
item.setCheckState(0)
self.lineEditCategory.setText('')
else:
it = self.listWidgetCategories.currentItem()
it.setText(self.lineEditCategory.text())
QLineEdit.keyPressEvent(self.lineEditCategory, e)
示例4: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, ev):
def appendText(text):
today = datetime.today()
day, hms = today.strftime("%Y-%m-%d"), today.strftime("%Y-%m-%d %H:%M:%S")
stamp = ''.join(["[", hms, "]"])
txt = ' -> '.join([stamp, text])
with open(day + ".txt", mode='a') as f:
f.write(txt + "\n")
if ev.key() not in [Qt.Key_Return, Qt.Key_Enter]:
QLineEdit.keyPressEvent(self, ev)
return
appendText(self.text())
self.setText("")
示例5: HeaderDisplay
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
class HeaderDisplay(QDialog):
def __init__(self, header):
super().__init__()
self.layout = QVBoxLayout(self)
self.setMinimumWidth(680)
self.resize(680, 500)
self.setWindowTitle('Header display')
self.cards = header.split('\n')
self.display = QPlainTextEdit('\n'.join(self.cards))
self.layout.addWidget(self.display)
self.display.setReadOnly(True)
self.display.setFocusPolicy(Qt.NoFocus)
self.display.setFont(QFont("Courier New", 10))
self.display.setPlaceholderText('No results found')
self.input_box = QLineEdit()
self.layout.addWidget(self.input_box)
self.input_box.setPlaceholderText('Enter search term')
self.input_box.textChanged[str].connect(self.onChanged)
self.input_box.setFont(QFont("Courier New", 10))
def keyPressEvent(self, event):
if event.key() in (Qt.Key_Up, Qt.Key_Down):
self.display.keyPressEvent(event)
if event.key() == Qt.Key_Escape:
self.close()
else:
self.input_box.keyPressEvent(event)
def onChanged(self, term):
if term == '':
search_results = self.cards
else:
search_results = [card for card in self.cards if term.lower() in card.lower()]
self.display.setPlainText('\n'.join(search_results))
示例6: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, event):
"""QWidget.keyPressEvent implementation. Catches Return, Up, Down, Ctrl+Backspace
"""
if event.key() in (Qt.Key_Enter, Qt.Key_Return):
if self._inlineCompletionIsSet:
self._applyInlineCompetion()
self.updateCurrentCommand.emit()
self.enterPressed.emit()
elif event.key() in (Qt.Key_Right, Qt.Key_End):
if self.selectedText():
self._applyInlineCompetion()
else:
QLineEdit.keyPressEvent(self, event)
self.updateCurrentCommand.emit()
elif event.key() == Qt.Key_Backspace and \
event.modifiers() == Qt.ControlModifier:
# Ctrl+Backspace. Usualy deletes word, but, for this edit should delete path level
self._clearInlineCompletion()
pos = self.cursorPosition()
textBefore = self.text()[:pos - 1] # -1 to ignore / at the end
slashIndex = textBefore.rfind('/')
spaceIndex = textBefore.rfind(' ')
if slashIndex != -1 and slashIndex > spaceIndex:
self._deleteToSlash()
else:
QLineEdit.keyPressEvent(self, event)
self._updateCurrentCommandTimer.start()
else:
oldTextBeforeCompletion = self.text()[:self.cursorPosition()]
inlineCompletion = self._inlineCompletion()
self._clearInlineCompletion()
QLineEdit.keyPressEvent(self, event)
# Inline completion will be recalculated later in the thread.
# But, this code helps to avoid flickering in case when user typed first letter of inline completion
textBeforeCompletion = self.text()[:self.cursorPosition()]
if inlineCompletion and \
len(oldTextBeforeCompletion) + 1 == len(textBeforeCompletion) and \
textBeforeCompletion.startswith(oldTextBeforeCompletion) and \
textBeforeCompletion[-1] == inlineCompletion[0]:
self.setInlineCompletion(inlineCompletion[1:]) # set rest of the inline completion
self._updateCurrentCommandTimer.start()
示例7: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.editingFinished.emit()
return QLineEdit.keyPressEvent(self, event)
示例8: lineKeyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def lineKeyPressEvent(self, event):
key = event.key()
if key == Qt.Key_Up or key == Qt.Key_Down:
self.glyphList.keyPressEvent(event)
else:
QLineEdit.keyPressEvent(self.glyphEdit, event)
示例9: keyPressEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import keyPressEvent [as 別名]
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_Escape:
self._clearSearch()
else:
QLineEdit.keyPressEvent(self, event)