简体   繁体   中英

HTML in QMessageBox

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM