Adding bullet points to a QTextEdit?
-
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 ); }