Results 1 to 5 of 5

Thread: [QTextCursor & QTextBlock] Inserting TextBlock without <br>

  1. #1
    Join Date
    Sep 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows Android

    Default [QTextCursor & QTextBlock] Inserting TextBlock without <br>

    Hello.

    I am trying to create IO rich-text based console widget using QTextBlock & QTextCursor.
    Is it possible to disable breakline character after inserting new QTextBlock?

  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: [QTextCursor & QTextBlock] Inserting TextBlock without <br>

    Hmm.... what sense would it make to do that?
    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 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: [QTextCursor & QTextBlock] Inserting TextBlock without <br>

    I want to append QTextEdit with rich text from userInput, USB or TTY Console
    with limited count of displayed characters (only newest data should be visible).
    I wondered to insert new block each time device has answered, but it is
    inserting new paragraph (with additional break line in document).

    My code:
    Qt Code:
    1. QScrollBar *p_scroll_bar = this->verticalScrollBar();
    2. bool bool_at_bottom = (p_scroll_bar->value() == p_scroll_bar->maximum());
    3. QTextCursor appendTextCursor = this->textCursor();
    4.  
    5. if(addBr)
    6. appendText.append("<br>");
    7.  
    8. appendText = QString("<font color = %1>%2</font>")
    9. .arg(this->_isDevice? this->_deviceColor.name() : this->_commandLineColor.name())
    10. .arg(appendText);
    11.  
    12. this->_containingText.append( appendText );
    13.  
    14. qDebug() << appendText;
    15.  
    16. appendTextCursor.movePosition(QTextCursor::End);
    17. appendTextCursor.insertBlock();
    18. appendTextCursor.beginEditBlock();
    19. appendTextCursor.insertHtml(appendText);
    20. appendTextCursor.endEditBlock();
    21.  
    22. if (bool_at_bottom)
    23. {
    24. p_scroll_bar->setValue(p_scroll_bar->maximum());
    25. }
    To copy to clipboard, switch view to plain text mode 

  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: [QTextCursor & QTextBlock] Inserting TextBlock without <br>

    So don't insert a new block but rather append to the existing one.
    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 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: [QTextCursor & QTextBlock] Inserting TextBlock without <br>

    Sure, I tried to append previous textBlock, but my widget worked extremely slow.
    By adding insertBlock(); widget worked properly, but it appends brs.

Similar Threads

  1. linebreaks in a textblock
    By tuli in forum Qt Programming
    Replies: 3
    Last Post: 3rd August 2014, 16:01
  2. How to set TextFormat of a TextBlock directly
    By wang9658 in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2012, 16:06
  3. Replies: 0
    Last Post: 5th January 2012, 22:32
  4. a Readonly Highlighted TextBlock in QTextEdit?
    By vertusd in forum Qt Programming
    Replies: 3
    Last Post: 21st July 2010, 16:50
  5. setVisible textblock in QTextEdit
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2010, 04:04

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.