【PyQt】redirect keyboard events to QTextEdit when it has no focus ?
本帖最后由 redstoneleo 于 2013-07-21 16:19:46 编辑 when the QTextEdit doesn’t have focus ,how to redirect keyboard events to the text editor ?
as This saves the user from clicking the text editor before entering text, making the application more user-friendly.
PyQt Python qt qt4 pyside
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class BoxLayout(QWidget):
def __init__(self, parent=None):
super(BoxLayout, self).__init__(parent)
# self.resize(100, 300)
ok = QPushButton("OK")
cancel = QPushButton("Cancel")
self.textEdit = QTextEdit()
vbox = QVBoxLayout()
vbox.addWidget(self.textEdit)
vbox.addWidget(ok)
vbox.addWidget(cancel)
self.setLayout(vbox)
app = QApplication(sys.argv)
qb = BoxLayout()
qb.show()
sys.exit(app.exec_())