本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.event方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.event方法的具體用法?Python QLineEdit.event怎麽用?Python QLineEdit.event使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.event方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lineEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import event [as 別名]
def lineEvent(self, event):
if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Tab:
if self.beginsWithBox.isChecked():
self.containsBox.toggle()
else:
self.beginsWithBox.toggle()
return True
else:
return QLineEdit.event(self.glyphEdit, event)
示例2: event
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import event [as 別名]
def event(self, event):
"""QObject.event implementation. Catches Tab events
"""
if event.type() == event.KeyPress and \
event.key() == Qt.Key_Tab:
if self.selectedText():
self.setCursorPosition(self.selectionStart() + len(self.selectedText()))
self.updateCurrentCommand.emit()
return True
else:
return QLineEdit.event(self, event)
示例3: event
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import event [as 別名]
def event(self, event):
event_type = event.type()
if event_type == QEvent.LayoutDirectionChange:
box_direction = QBoxLayout.RightToLeft if self.isRightToLeft() else QBoxLayout.LeftToRight
self.left_layout.setDirection(box_direction)
self.right_layout.setDirection(box_direction)
elif event_type == QEvent.DynamicPropertyChange:
property_name = event.propertyName()
if property_name == 'widgetSpacing':
self.left_layout.setSpacing(self.widgetSpacing)
self.right_layout.setSpacing(self.widgetSpacing)
self._update_text_margins()
elif property_name == 'inactiveText':
self.update()
return QLineEdit.event(self, event)
示例4: event
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import event [as 別名]
def event(self, evt):
"""
Public method to handle events.
@param evt reference to the event (QEvent)
@return flag indicating, whether the event was recognized (boolean)
"""
if evt.type() == QEvent.LayoutDirectionChange:
if self.isRightToLeft():
self.__mainLayout.setDirection(QBoxLayout.RightToLeft)
self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
else:
self.__mainLayout.setDirection(QBoxLayout.LeftToRight)
self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
self.__rightLayout.setDirection(QBoxLayout.LeftToRight)
return QLineEdit.event(self, evt)
示例5: QtKeySequenceEdit
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import event [as 別名]
class QtKeySequenceEdit(QWidget):
keySequenceChangedSignal = pyqtSignal(QKeySequence)
def __init__(self,parent=None):
super(QtKeySequenceEdit, self).__init__(parent)
self.m_keySequence = QKeySequence()
self.m_num = 0
self.m_lineEdit = QLineEdit(self)
layout = QHBoxLayout(self)
layout.addWidget(self.m_lineEdit)
layout.setContentsMargins(0, 0, 0, 0)
self.m_lineEdit.installEventFilter(self)
self.m_lineEdit.setReadOnly(True)
self.m_lineEdit.setFocusProxy(self)
self.setFocusPolicy(self.m_lineEdit.focusPolicy())
self.setAttribute(Qt.WA_InputMethodEnabled)
def eventFilter(self, o, e):
if o == self.m_lineEdit and e.type() == QEvent.ContextMenu:
c = e
menu = self.m_lineEdit.createStandardContextMenu()
actions = menu.actions()
for action in actions:
action.setShortcut(QKeySequence())
actionString = action.text()
pos = actionString.rfind('\t')
if (pos > 0):
actionString = actionString[:pos]
action.setText(actionString)
actionBefore = None
if (len(actions) > 0):
actionBefore = actions[0]
clearAction = QAction(self.tr("Clear Shortcut"), menu)
menu.insertAction(actionBefore, clearAction)
menu.insertSeparator(actionBefore)
clearAction.setEnabled(not len(self.m_keySequence)<=0)
clearAction.triggered.connect(self.slotClearShortcut)
menu.exec(c.globalPos())
e.accept()
return True
return super(QtKeySequenceEdit, self).eventFilter(o, e)
def slotClearShortcut(self):
if len(self.m_keySequence) <= 0:
return
self.setKeySequence(QKeySequence())
self.keySequenceChangedSignal.emit(self.m_keySequence)
def handleKeyEvent(self, e):
nextKey = e.key()
if (nextKey == Qt.Key_Control or nextKey == Qt.Key_Shift or
nextKey == Qt.Key_Meta or nextKey == Qt.Key_Alt or
nextKey == Qt.Key_Super_L or nextKey == Qt.Key_AltGr):
return
nextKey |= self.translateModifiers(e.modifiers(), e.text())
k0 = 0
k1 = 0
k2 = 0
k3 = 0
l = len(self.m_keySequence)
if l==1:
k0 = self.m_keySequence[0]
elif l==2:
k0 = self.m_keySequence[0]
k1 = self.m_keySequence[1]
elif l==3:
k0 = self.m_keySequence[0]
k1 = self.m_keySequence[1]
k2 = self.m_keySequence[2]
elif l==4:
k0 = self.m_keySequence[0]
k1 = self.m_keySequence[1]
k2 = self.m_keySequence[2]
k3 = self.m_keySequence[3]
if self.m_num==0:
k0 = nextKey
k1 = 0
k2 = 0
k3 = 0
elif self.m_num==1:
k1 = nextKey
k2 = 0
k3 = 0
elif self.m_num==2:
k2 = nextKey
k3 = 0
elif self.m_num==3:
k3 = nextKey
else:
pass
self.m_num += 1
if (self.m_num > 3):
self.m_num = 0
self.m_keySequence = QKeySequence(k0, k1, k2, k3)
self.m_lineEdit.setText(self.m_keySequence.toString(QKeySequence.NativeText))
e.accept()
#.........這裏部分代碼省略.........
示例6: FileEdit
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import event [as 別名]
class FileEdit(QWidget):
filePathChanged = pyqtSignal(str)
def __init__(self, parent = None):
super().__init__(parent)
self.mFilter = ''
self.mErrorTextColor = Qt.red
layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
self.mLineEdit = QLineEdit(self)
self.mLineEdit.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred))
self.mOkTextColor = self.mLineEdit.palette().color(QPalette.Active, QPalette.Text)
button = QToolButton(self)
button.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred))
button.setFixedWidth(20)
button.setText("...")
layout.addWidget(self.mLineEdit)
layout.addWidget(button)
self.setFocusProxy(self.mLineEdit)
self.setFocusPolicy(Qt.StrongFocus)
self.setAttribute(Qt.WA_InputMethodEnabled)
self.mLineEdit.textEdited.connect(self.filePathChanged)
self.mLineEdit.textChanged.connect(self.validate)
button.clicked.connect(self.buttonClicked)
def setFilePath(self, filePath):
if (self.mLineEdit.text() != filePath):
self.mLineEdit.setText(filePath)
def filePath(self):
return self.mLineEdit.text()
def setFilter(self, filter):
self.mFilter = filter
def focusInEvent(self, e):
self.mLineEdit.event(e)
if (e.reason() == Qt.TabFocusReason or e.reason() == Qt.BacktabFocusReason):
self.mLineEdit.selectAll()
super().focusInEvent(e)
def focusOutEvent(self, e):
self.mLineEdit.event(e)
super().focusOutEvent(e)
def keyPressEvent(self, e):
self.mLineEdit.event(e)
def keyReleaseEvent(self, e):
self.mLineEdit.event(e)
def validate(self, text):
if QFile.exists(text):
textColor = self.mOkTextColor
else:
textColor = self.mErrorTextColor
palette = self.mLineEdit.palette()
palette.setColor(QPalette.Active, QPalette.Text, textColor)
self.mLineEdit.setPalette(palette)
def buttonClicked(self):
filePath, _ = QFileDialog.getOpenFileName(self.window(), self.tr("Choose a File"), self.mLineEdit.text(), self.mFilter)
if filePath=='':
return
self.mLineEdit.setText(filePath)
self.filePathChanged.emit(filePath)