【问题标题】:How to write on multiple lines in a QMessageBox in QtCreator?如何在 QtCreator 的 QMessageBox 中多行书写?
【发布时间】:2011-10-17 06:19:41
【问题描述】:

我希望在消息框中包含以下几行:

name:
surname:
data:
test:

在每个: 之后,我将以编程方式填充该行。我想问一下如何在 QMessageBox 中有这个结构。有可能吗?

我是 Qt Creator 的初学者。目前我学会了这样做:

QMessageBox noc;
            std::string s= "hello1";
            QString er = s.c_str();
            noc.setText(er);
            noc.exec()

【问题讨论】:

    标签: c++ qt qt-creator qmessagebox


    【解决方案1】:
    QString str;
    
    str = QString("name: %1\nsurname: %2\ndata: %3").arg(...).arg(...).arg(...);
    QMessageBox::information(0, "Title", str);
    

    看看QMessageBox::information()QString::arg()

    【讨论】:

      【解决方案2】:

      只需在每个字符串的末尾添加“\n”...

      QMessageBox noc;
      QString er = tr("name: %1\nsurname: %2\ndata: %3\ntest:%4").arg(...);
      noc.setText(er);
      noc.exec();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-16
        • 2015-03-17
        • 1970-01-01
        • 2011-04-02
        • 2014-04-30
        • 2021-11-23
        • 2012-03-03
        • 1970-01-01
        相关资源
        最近更新 更多