C++ 自定义QLineEdit的事件QComboBox
问题:我在自定义C++ 自定义QLineEdit的事件QComboBox,c++,qt,qt5,qcombobox,qlineedit,C++,Qt,Qt5,Qcombobox,Qlineedit,问题:我在自定义QComboBox中的QLineEdit上有一个自定义事件,在我需要时,只有特定的事件从QComboBox传递到QLineEdit。我无法通过这项法案 我希望当事件传递到QComboBox时,它将被传递到QComboBox->lineEdit() QCustomCombo::QCustomCombo(): m_lineEdit(新QCustomLineEdit) { 可编辑设置(真); setLineEdit(m_lineEdit); } boolqcustomcombo::事件
QComboBox
中的QLineEdit
上有一个自定义事件,在我需要时,只有特定的事件从QComboBox
传递到QLineEdit
。我无法通过这项法案
我希望当事件传递到QComboBox
时,它将被传递到QComboBox->lineEdit()
QCustomCombo::QCustomCombo():
m_lineEdit(新QCustomLineEdit)
{
可编辑设置(真);
setLineEdit(m_lineEdit);
}
boolqcustomcombo::事件(QEvent*event)
{
如果(事件->类型()==QEvent::按键)
{
QKeyEvent*keyEvent=静态广播(事件);
如果(keyEvent->key()==Qt::key\u选项卡)
{
//传递到lineEdit();
//我尝试过“返回真/假和QWidget::事件(event)”
//我也试过注释QCustomCombo::event,同样的问题
}
}
返回QWidget::事件(event);
}
QCustomLineEdit
boolqcustomlineedit::事件(QEvent*event)
{
如果(事件->类型()==QEvent::按键)
{
QKeyEvent*keyEvent=静态广播(事件);
如果(keyEvent->key()==Qt::key\u选项卡)
{
//做定制的东西
返回true;
}
if(keyEvent->key()==Qt::key\u Right)
{
//做定制的东西
返回true;
}
}
返回QWidget::事件(event);
}
QLineEdit
有一个用于左右箭头和选项卡的自定义事件。只有箭才能通过。但是我不能把账单转到它上面 使用QApplication::notify
bool QCustomCombo::event(QEvent * event)
{
if(event->type() == QEvent::KeyPress)
{
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
{
qApp->notify(m_lineEdit, event);
return true;
}
}
return QWidget::event(event);
}
boolqcustomcombo::事件(QEvent*event)
{
如果(事件->类型()==QEvent::按键)
{
QKeyEvent*keyEvent=静态广播(事件);
如果(keyEvent->key()==Qt::key\u选项卡)
{
qApp->通知(m_lineEdit,事件);
返回true;
}
}
返回QWidget::事件(event);
}
使用QApplication::notify
bool QCustomCombo::event(QEvent * event)
{
if(event->type() == QEvent::KeyPress)
{
QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab)
{
qApp->notify(m_lineEdit, event);
return true;
}
}
return QWidget::event(event);
}
boolqcustomcombo::事件(QEvent*event)
{
如果(事件->类型()==QEvent::按键)
{
QKeyEvent*keyEvent=静态广播(事件);
如果(keyEvent->key()==Qt::key\u选项卡)
{
qApp->通知(m_lineEdit,事件);
返回true;
}
}
返回QWidget::事件(event);
}
我希望当一个事件传递到QComboBox时,它将被传递到
QComboBox->lineEdit()
他是你的朋友。它允许对象A在另一个对象B上安装事件过滤器,以便在调用对象B的event(QEvent*)
方法之前,首先调用对象A的eventFilter(QObject*,QEvent*)
方法,以便对象A可以决定如何处理事件(以及事件是否应随后传递给对象B)
您可以使用它,这样您的CustomCombo
就可以看到直接进入“QComboBox”的事件并对其作出反应
我希望当一个事件传递到QComboBox时,它将被传递到
QComboBox->lineEdit()
它允许对象A在另一个对象B上安装事件过滤器,以便在调用对象B的event(QEvent*)
方法之前,首先调用对象A的eventFilter(QObject*,QEvent*)
方法,以便对象A可以决定如何处理事件(以及事件是否应随后传递给对象B)
您可以使用它,这样您的
CustomCombo
就可以看到直接进入“QComboBox”的事件并对其作出反应。如何访问qApp函数?我尝试了QCustomCombo:private QApplication
,但这破坏了我的connect()
行。QCombo位于main.cpp创建的mainwindow.cpp内(main.cpp是我拥有QApplication实例的地方)。@DevilGale无需继承,只需包含标题:\include
QApplication::instance()是一个可与qApp宏一起使用的单例。如何访问qApp函数?我尝试了QCustomCombo:private QApplication
,但这打断了我的connect()
行。QCombo位于main.cpp创建的main window.cpp内(main.cpp是我拥有QApplication实例的地方)@DevilGale无需继承,只需包含标题:#include
QApplication::instance()
是可与qApp宏一起使用的单例。