Qt 覆盖文本输入框中tab键的默认功能
1.新建类TextEdit继承自QTextEdit;
2.重写event事件;
3.判断tab键按下,return false;
TextEdit::TextEdit(QWidget* paernt) : QTextEdit(parent) { } bool TextEdit::event(QEvent* event) { if(event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = (QKeyEvent*)event; if(keyEvent->key() == Qt::Key_Tab) { return false; } } return QTextEdit::event(event); }