use the eventfilter and return true if you receive the tab key, if you dont filter it you will do 4 spaces and then when the input box receives the tab it will add another tab
edit:
made some code
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->lineEdit->installEventFilter(this);
}
{
if(event
->type
() == QEvent::KeyPress) //event is installed on the lineedit so not checking object {
QKeyEvent *key
= dynamic_cast<QKeyEvent
*>
(event
);
if(key && key->key() == Qt::Key_Tab)
{
ui->lineEdit->insert("!!!!");
return true;
}
}
return false;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->lineEdit->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::KeyPress) //event is installed on the lineedit so not checking object
{
QKeyEvent *key = dynamic_cast<QKeyEvent*>(event);
if(key && key->key() == Qt::Key_Tab)
{
ui->lineEdit->insert("!!!!");
return true;
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks