gpt4 book ai didi

python - QComboBox 忽略键盘输入

转载 作者:行者123 更新时间:2023-11-30 05:37:26 25 4
gpt4 key购买 nike

QComboBox 的下拉列表打开时,键盘输入被用作(不是特别聪明的)搜索元素的方式。我想禁用它并将键盘事件的处理传播到父小部件。怎么办呢?我已经尝试在子类中重新实现 keyPressEvent 但显然这不起作用,因为该函数不是在有键盘输入时被调用的函数。

最佳答案

当显示弹出窗口时,接收事件的是 QComboBox 的 View ,而不是框本身。您可以在其上放置一个事件过滤器:

class Filter : public QObject
{
Q_OBJECT
public:
bool eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
return true;
}
return false;
}
};

<...>

QComboBox box;
box.view()->installEventFilter(new Filter());

关于python - QComboBox 忽略键盘输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33231658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com