简体   繁体   English

如何调用QCombobox的linedit的KeyPressEvent(QKeyEvent *)?

[英]How Call the KeyPressEvent(QKeyEvent *) of linedit of QCombobox?

I have a QComboBox , which is editable, I implemented the keyPressEvent(QKeyEvent *) method, but it does not seem to fire this method. 我有一个QComboBox ,它是可编辑的,我实现了keyPressEvent(QKeyEvent *)方法,但是它似乎没有触发此方法。

I can think of the only reason this happens is that whatever editing that occurs is actually happening in lineEdit object and We should implement keyPressEvent(QKeyEvent *) of line Edit . 我可以想到发生这种情况的唯一原因是, 实际上发生在lineEdit对象中的任何编辑都发生了,我们应该实现Edit行的keyPressEvent(QKeyEvent *) How can I achieve this? 我该如何实现?

You have two options: 您有两种选择:

  1. Install an event filter on the lineEdit widget. lineEdit小部件上安装事件过滤器。

  2. Use setLineEdit to replace the existing widget with your own subclass that reimplements the event handler. 使用setLineEdit将现有的小部件替换为自己的子类,该子类可重新实现事件处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM