There is a qTextBrowser element on the form, to which elements are added as follows:

 for(int i = 0; i < MAX_STATE;i++) { ui->textBrowser->insertPlainText(QString::number(m[i].nextstate[j])); ui->textBrowser->insertPlainText(","); ui->textBrowser->insertPlainText(QString::number(m[i].output[j])); ui->textBrowser->insertPlainText(" "); ui->textBrowser->append(""); } 

Go to the next line and has the form:

enter image description here

How to make the columns appear exactly? Something like std::setw , only for qTextBrowser ?

  • Well, maybe "\t" will save you instead of spaces. If not, no way. Beat on separate column widgets. - D-side

1 answer 1

Make your font monospaced with SetFont() .

After that, your TextBrowser will not differ from the console - output your text to std::stringstream using your usual setw , and then get a string from it using the str() method and using QString::fromStdString() surpass it in QString , which Already it will be possible to drive into the browser.

  • Why mix std:: and Qt ? There is a QTextStream::setFieldWidth . - αλεχολυτ
  • @alexolut has two approaches to work - use std everywhere and dock with Qt only when you need to access the GUI, or use Qt everywhere, as you suggest. Almost all libraries have connections to std, but there are no connections to Qt. - gbg
  • The last sentence did not quite understand. I myself am not a supporter of using Qt wrappers where you can use std . But this is primarily for simple functions, not classes. For example, starting with Qt5 , developers finally realized that they should not produce unnecessary entities, but rather use std . But in the current case, I am still in the absence of mixing Qt and std , precisely because of the use of non-trivial classes, and not simple algorithms. - αλεχολυτ
  • @alexolut In my last sentence I said that when using several libraries there are "translation difficulties", but there is almost always a solution with an intermediate in the form of std. I suggested using std, since the author is already familiar with it. At the same time, to get acquainted with the Qt bikes would have to go into the documentation. - gbg