Pergunta

I have an action which create QMessageBox. In that dialog I want to print a list, which contains several items. I have the following code:

void MainWindow::onAboutActivated(){
qDebug() << "about";
QMessageBox::about(this,
                   "Autor: \n"
                   "\n"
                   "Umoznuje:"
                   "<ul>"
                   "<li> Item 1 </li>"
                   "<li> Item 2 </li>"
                   "<li> Item 3 </li>"
                   "</ul>");

However this does not print the list, but text with html tags. How can I print the list? Any ideas?

Foi útil?

Solução

Don't mix newlines \n with html-tags. Change the newlines to <br> and then the text format is automatically recognized.

Outras dicas

It seems you are setting the dialog title instead of dialog contents. This works for me:

void MainWindow::onAboutActivated(){
qDebug() << "about";
QMessageBox::about(this, "Dialog Title",
                   "Autor: \n"
                   "\n"
                   "Umoznuje:"
                   "<ul>"
                   "<li> Item 1 </li>"
                   "<li> Item 2 </li>"
                   "<li> Item 3 </li>"
                   "</ul>");

The default text format for QMessageBox is Qt::AutoText which should detect html tags inside your string, so you should be able to continue using the about static method without the need to instantiate a QMessageBox object.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top