PDA

View Full Version : Parenthesis Comparision with Enter key Event



parulkalra14
22nd January 2014, 08:22
I want whenever open parenthesis occurs({) cursor will move to next line and four spaces ahead and this must be recursively done (means when again parenthesis occurs then cursor will again move to next line but now cursor will move eight spaces ahead ). KeyPress Enter Code is working fine but how to compare text parenthesis along with key event?

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::KeyPress){
QKeyEvent *key = static_cast<QKeyEvent*>(event);

if(key && key->key() == Qt::Key_Enter||key && key->key() == Qt::Key_Return)
{

textEdit->insertPlainText("\n\t");
return true;
}
}return false;
}

tabstopwidth is set to 4.

anda_skoa
22nd January 2014, 09:43
You will need to start looking into QTextDocument for advanced text manipulation.

Cheers,
_

StrikeByte
22nd January 2014, 11:39
QTextDocument is the best way i think, but if you dont want to use it you can increase a counter when typed a { and decrease the count when } is typed
I assume that } removes the indent (like source code editors do)