PDA

View Full Version : [QTextCursor & QTextBlock] Inserting TextBlock without <br>



zavafoj
1st October 2014, 11:11
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?

wysota
1st October 2014, 11:46
Hmm.... what sense would it make to do that?

zavafoj
1st October 2014, 11:58
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:



QScrollBar *p_scroll_bar = this->verticalScrollBar();
bool bool_at_bottom = (p_scroll_bar->value() == p_scroll_bar->maximum());
QTextCursor appendTextCursor = this->textCursor();

if(addBr)
appendText.append("<br>");

appendText = QString("<font color = %1>%2</font>")
.arg(this->_isDevice? this->_deviceColor.name() : this->_commandLineColor.name())
.arg(appendText);

this->_containingText.append( appendText );

qDebug() << appendText;

appendTextCursor.movePosition(QTextCursor::End);
appendTextCursor.insertBlock();
appendTextCursor.beginEditBlock();
appendTextCursor.insertHtml(appendText);
appendTextCursor.endEditBlock();

if (bool_at_bottom)
{
p_scroll_bar->setValue(p_scroll_bar->maximum());
}

wysota
1st October 2014, 13:08
So don't insert a new block but rather append to the existing one.

zavafoj
17th October 2014, 17:14
Sure, I tried to append previous textBlock, but my widget worked extremely slow.
By adding insertBlock(); widget worked properly, but it appends brs.