双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

【PyQt】redirect keyboard events to QTextEdit when it has no focus ?

redstoneleo redstoneleo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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.



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_())
...全文
评论 1
收藏 已收藏
分享
返回顶部
redstoneleo
脚本语言 37,738 成员 34,208 内容