PDA

View Full Version : trying to indent



jajdoo
19th July 2010, 15:02
I'm trying to indent lines within QPlainTextEdit depending on '{' and '} characters'. whenever i catch a blockCountChanged signal, i do this:
(from within a class derived from QPlainTextEdit)

int state = 0;
for( int i=0 ; i<=document()->blockCount() ; i++ )
{
if( document()->findBlock(i).text().indexOf(QRegExp("\\{"))!=-1 )
state+=1;
if( document()->findBlock(i).text().indexOf(QRegExp("\\}"))!=-1 )
state+=1;
document()->findBlock(i).setUserState(state);
}
for(int i=0; i < textCursor().block().userState() ; i++)
textCursor().insertText(QString("\t"));
unfortunately it seems to act randomly.. cant seem to figure out why. ideas?

ChrisW67
19th July 2010, 23:25
Line 7... did you want to reduce the indent?

Are you interested in { } anywhere in the line or only the start/end? Do you really need a QRegExp when looking for a simple single character?