Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding bullet points to a QTextEdit?
Qt 6.11 is out! See what's new in the release blog

Adding bullet points to a QTextEdit?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 7.4k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by VRonin
      #2

      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 );
      }
      
      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Yep, works perfectly!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved