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?
(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?