QWidget 操作汇总
作者:互联网
QT中的事件过滤器
处理事件过滤
bool eventFilter(QObject *watched, QEvent *event)
{
if(watched == ui->lineEdit||watched == ui->lineEdit_2||
ui->lineEdit_3||ui->lineEdit_4||ui->lineEdit_5||ui->lineEdit_6)
{
if(event->type() == QEvent::KeyPress)
{
QKeyEvent*e = static_cast<QKeyEvent*>(event);
if(e->key() == Qt::Key_Space)
{
focusNextChild();
}
return false; // reture false 不会拦截其他事件,return true 会拦截其他事件
}
}
return QWidget::eventFilter(watched,event);
}
安装事件过滤器
ui->lineEdit->installEventFilter(this);
ui->lineEdit_5->installEventFilter(this);
ui->lineEdit_2->installEventFilter(this);
ui->lineEdit_3->installEventFilter(this);
ui->lineEdit_4->installEventFilter(this);
ui->lineEdit_6->installEventFilter(this);
6个lineEdit 输入数字后按空格键焦点会跳到下一个控件
标签:installEventFilter,return,汇总,ui,QWidget,watched,操作,lineEdit,event 来源: https://blog.csdn.net/qq_22878985/article/details/120341607