Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Adding bullet points to a QTextEdit?

    General and Desktop
    2
    4
    5917
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LiamMaru 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.

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by VRonin

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

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • L
          LiamMaru last edited by

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

          1 Reply Last reply Reply Quote 0
          • L
            LiamMaru last edited by

            Yep, works perfectly!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post