i want to know is there any reference for make shortcut key to edit text in a line edit in PyQt4 python. i have been looking in google for almost 2 day but i can't find any relevant info about this. it's will be better if you gift me code sample. any suggestion would be welcomed, Thank's
Creates a QShorcut
and connect to the function setFocus()
from PyQt4 import QtGui
class Widget(QtGui.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__(parent=parent)
self.layout = QtGui.QVBoxLayout(self)
self.line = QtGui.QLineEdit()
self.button = QtGui.QPushButton("Button")
self.layout.addWidget(self.button)
self.layout.addWidget(self.line)
shortcut = QtGui.QShortcut(QtGui.QKeySequence("Ctrl+O"), self)
shortcut.activated.connect(self.line.setFocus)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
Before Ctrl+O
After Ctrl+O
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.