如何为可编辑的QComboBox覆盖KeyPressEvent? [英] How-to override KeyPressEvent for an editable QComboBox?

查看:221
本文介绍了如何为可编辑的QComboBox覆盖KeyPressEvent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ValidableComboBox的类,直接从QComboBox派生.

I have a class named ValidableComboBox that derives directly from QComboBox.

每个ValidableComboBox实例都将setEditable()设置为true.我的目标是添加一些信号,只要有人按下QComboBox中的回车键,就会发出该信号.

Every instance of ValidableComboBox has setEditable() set to true. My goal is to add some signal that will be emitted whenever someone presses return key in the QComboBox.

为此,我在ValidableComboBox中重新实现了void KeyPressEvent(QKeyEvent* e).但是,当我在组合框中键入内容时,似乎永远都不会调用它.

To do so, I reimplemented void KeyPressEvent(QKeyEvent* e) in ValidableComboBox. However, it seems that it never gets called when I type something into the combobox.

有没有办法实现这一目标?我所做的事情可能出什么问题了?

Is there a way to achieve this ? What could possibly be wrong with what I have done ?

谢谢.

推荐答案

您似乎在kode中使用的功能具有Kapital K,而不是小k,好吗? :-D

The funktion you've seem to be using in your kode has a Kapital K, instead of a small k, ok? :-D

这篇关于如何为可编辑的QComboBox覆盖KeyPressEvent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆