Adding bullet points to a QTextEdit?



  • 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.



  • 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 );
    

    }
    @



  • Thanks Volker, I'll put that in and see what comes out.



  • Yep, works perfectly!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.