Adding bullet points to a QTextEdit?
-
wrote on 14 Apr 2011, 09:10 last edited by
Is there a way to turn a set of selected paragraphs into bullet points and vice versa? I'd like to be able to add bullet points to my custom rich text editor.
-
wrote on 14 Apr 2011, 11:56 last edited by VRonin 12 Aug 2017, 09:20
To create a list from existing paragraphs:
//QTextListFormat::Style style = QTextListFormat::ListStyleUndefined; //QTextListFormat::Style style = QTextListFormat::ListDecimal; QTextListFormat::Style style = QTextListFormat::ListDisc; QTextCursor cursor = textEdit->textCursor(); QTextListFormat listFormat; listFormat.setStyle( style ); cursor.createList( listFormat );
The cursor retrieved from the text edit contains a selection. The format is applied to this selection.
To reset a list to plain text:
QTextCursor cursor = textEdit->textCursor(); QTextList *list = cursor.currentList(); if( list ) { QTextListFormat listFormat; listFormat.setIndent( 0 ); listFormat.setStyle( style ); list->setFormat( listFormat ); for( int i = list->count() - 1; i >= 0 ; --i ) list->removeItem( i ); }
-
wrote on 14 Apr 2011, 13:00 last edited by
Thanks Volker, I'll put that in and see what comes out.
-
wrote on 16 Apr 2011, 03:33 last edited by
Yep, works perfectly!
1/4