Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the whole text from text edit QT

I am trying to get the text from a text edit and store it in a QString .

When I write this

QString text = ui->textEdit->toPlainText();

it only reads the text before the first '\n' So how can I get the whole text with '\n's in it.

This is being called from a slot like this: -

void MainWindow::on_pushButton_clicked() 
{ 
    QString text = ui->textEdit->toPlainText(); 
    ui->label_2->setText(text); 
}
like image 956
samvel1024 Avatar asked Oct 17 '13 12:10

samvel1024


People also ask

How do I get text from QTextEdit?

QTextEdit does not have any text() method, if you want to get the text you must use toPlainText() , if you want to clean the text it is better to use clear() since it makes it more readable.

How do you use text browser QT?

If you want to provide your users with an editable rich text editor, use QTextEdit. If you want a text browser without hypertext navigation use QTextEdit, and use QTextEdit::setReadOnly() to disable editing. If you just need to display a small piece of rich text use QLabel.

What is text Edit in Qt?

QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML-style tags, or Markdown format. It is optimized to handle large documents and to respond quickly to user input. QTextEdit works on paragraphs and characters.

How do you insert a textbox in Qt?

Using Rich Text You can use rich text in the Text and Text Input components. To open the rich text editor, select the (Edit) button in Properties > Character > Text.


1 Answers

Turning my comment into an answer

Make sure that the label is high enough to actually display multi-line text.

like image 68
Angew is no longer proud of SO Avatar answered Sep 19 '22 14:09

Angew is no longer proud of SO