Results 1 to 3 of 3

Thread: How to remove QTextListFormat text style?

  1. #1
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default How to remove QTextListFormat text style?

    Hi,

    I want to write a small text edit application, where the user can format text. But I have a problem with QTextListFormat. Its no problem to create bullets with QTextListFormat::setStyle but I have no idea how to remove this formation.

    You can see this problem even in the official Qt textedit demo. Start the demo, select text, select for example the "Bullet List (Square)" format and the text will be formatted with bullets. Select "Standard" and nothing happens.
    Is it possible to remove this formation?

    Greetings,
    Fred

  2. #2
    Join Date
    Jul 2012
    Location
    Florianópolis, Brazil
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to remove QTextListFormat text style?

    Yes, it's perfectly possible. The question was posted years ago, but I'm replying for future references.

    To remove a list from a text block, you must call the list's remove() function, passing the block as a parameter. The example below shows how you could do that:

    Qt Code:
    1. //let textEdit be your QTextEdit object. get its text cursor
    2. QTextCursor cursor = textEdit->textCursor();
    3.  
    4. //get the cursor's current list, which you want to remove from the text.
    5. QTextList* currentList = cursor.currentList();
    6.  
    7. //get the current block, which you want to remove from the current list
    8. QTextBlock currentBlock = cursor.block();
    9.  
    10. //call the list's remove() function, passing the block as a parameter
    11. currentList->remove(currentBlock);
    12.  
    13. //the list is now removed, but you still have to remove the list identation
    14. QTextBlockFormat blockFormat = cursor.blockFormat();
    15. blockFormat.setIndent(0);
    16. cursor.setBlockFormat(blockFormat);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2017
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to remove QTextListFormat text style?

    In the official Qt textedit demo you have code like this:

    QTextBlockFormat bfmt = QTextBlockFormat();
    bfmt.setObjectIndex(-1);
    cursor.mergeBlockFormat(bfmt);

    And that doesent work. But if you set ObjectIndex to zero like this:
    bfmt.setObjectIndex(0);

    that works.

Similar Threads

  1. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 13:48
  2. Can style sheets control rich text elements?
    By wrdieter in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2009, 14:47
  3. Replies: 3
    Last Post: 3rd May 2009, 09:58
  4. Replies: 1
    Last Post: 3rd September 2008, 15:16
  5. Qt class showing text area/text edit
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2008, 13:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.