Results 1 to 6 of 6

Thread: How to change current line format in QTextEdit?

  1. #1
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to change current line format in QTextEdit?

    Hi, there! I want to find out how to change current line format in QTextEdit?

    In the document I read that formatting can be applied to the current text document using the setCharFormat(), mergeCharFormat(), setBlockFormat() and mergeBlockFormat() functions. If the cursor has no selection, current block format will be changed. But in my application, the current block in which cursor is couldn't be changed. May I missed something? Then how could I change current block format which has no selection?

    Thank you all!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change current line format in QTextEdit?

    What have you tried so far?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change current line format in QTextEdit?

    Here is what did:
    Qt Code:
    1. QTextCursor cursor = this->textCursor();
    2. blockFmt.setNonBreakableLines(true);
    3. blockFmt.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
    4. charFmt.setFont(data->visualFont());
    5. if(!cursor.hasSelection()) {
    6. cursor.beginEditBlock();
    7. cursor.setBlockFormat(blockFmt);
    8. cursor.mergeBlockCharFormat(charFmt);
    9. QTextBlock block = cursor.block();
    10. block.setUserData(data);
    11. cursor.endEditBlock();
    12. }
    To copy to clipboard, switch view to plain text mode 

    What I want to do is: change current line's format if there is no selection. So if cursor.hasSelection() is false, I just merge new format to block chars. But this does not work.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change current line format in QTextEdit?

    You have to set the cursor back on the text edit.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change current line format in QTextEdit?

    I added this->setTextCorsor(cursor); after cursor.endEditBlock();, but it still doesn't work. In fact, after adding this, the whole block becomes invisible.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change current line format in QTextEdit?

    What is the ultimate result you want to receive? Do you wish to change the format of the whole block or what exactly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 20th February 2012, 21:58
  2. QTextArea getting the current line of visible area(scroll)
    By ubuntudevelop78 in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2009, 06:19
  3. QTextEdit current cursor text format
    By afail in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 14:24
  4. How to get current word in Qtextedit
    By iamjayanth in forum Qt Programming
    Replies: 5
    Last Post: 6th April 2009, 08:57
  5. Current char in QTextEdit
    By jlbrd in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 09:30

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.