[SOLVED] Indent multiple lines with TAB in a QPlainTextEdit
I am very new to Qt and my plan is to write a little text editor for a better understanding in Qt. But I have a little problem with the indentation and the TAB key.
Is there an easy way to indent multiple (selected) lines with the tab key ? At the moment, it replaces the selected lines with a tab - example:
But the default behaviour is this, because the 4 lines are replaced with a tab (because they are selected):
Is there a way to override this behaviour or to write an indent/outdent function ?
You should subclass QPlainTextEdit and override following method:
@virtual void QPlainTextEdit::keyPressEvent ( QKeyEvent * e )@
Catch the tab key as described in http://doc.qt.digia.com/qt/qwidget.html#keyPressEvent
Then you should iterate through selected lines and prepend tab character ('\t').
You can obtain the selection through a QTextCursor object, which in turn you can obtain by method
@QTextCursor QPlainTextEdit::textCursor () const@
Okay, thank you, that's a good starting point
-PS: Is there a button to mark the thread as solved ?- Titel