【问题标题】:An "About" message box for a GUI with Qt带有 Qt 的 GUI 的“关于”消息框
【发布时间】:2010-03-17 18:26:45
【问题描述】:
    QMessageBox::about( this, "About Application",
    "<h4>Application is a one-paragraph blurb</h4>\n\n"
"Copyright 1991-2003 Such-and-such. "
"For technical support, call 1234-56789 or see\n"
"<a href=\"http://www.such-and-such.com\">http://www.such-and-such.com</a>" );

这段代码正在创建我想要的关于消息框,但有两个例外:

1) 我想用 aaa.png 文件更改消息框中的图标

2) 我希望链接可以点击。它看起来像超链接(它是蓝色并带下划线),但鼠标点击不起作用

有什么想法吗?

【问题讨论】:

    标签: c++ user-interface qt qt4 messagebox


    【解决方案1】:

    我认为您应该为您的 about 小部件创建一个自定义 QWidget。通过这种方式,您可以随心所欲地放置小部件。例如,您可以使用openExternalLinks 属性放置QLabel 以获得可点击链接。

    要在QWidget 上显示自定义图像,此example 可能会有所帮助。

    【讨论】:

      【解决方案2】:

      对于图标,您只需设置应用程序图标即可。像这样的:

      QApplication::setWindowIcon(QIcon(":/aaa.png")); // from a resource file
      

      至于让链接可点击,我认为不能直接使用QMessageBox::about API 完成。

      【讨论】:

      • 好的,你能告诉我,一般来说,我们如何创建一个内部带有超链接文本的小部件?
      【解决方案3】:
      QMessageBox msgBox;
      msgBox.setTextFormat(Qt::RichText); // this does the magic trick and allows you to click the link
      msgBox.setText("Text<br /><a href=\"http://www.such-and-such.com\">http://www.such-and-such.com</a>");
      msgBox.setIcon(yourIcon);
      msgBox.exec();
      

      【讨论】:

        【解决方案4】:

        为了将来参考,文档声明textFormat is Qt::AutoText 的默认类型。文档进一步指出Qt::AutoText is interpreted as Qt::RichText if Qt::mightBeRichText() returns true, otherwise as Qt::PlainText。最后,mightBeRichText uses a fast and therefore simple heuristic. It mainly checks whether there is something that looks like a tag before the first line break. 因此,由于您的第一行没有标签,它假定它是纯文本。使用msgBox.setTextFormat(Qt::RichText); 将其显式设置为 RichText 以使其采取相应措施。

        【讨论】:

          【解决方案5】:
          【解决方案6】:

          ma​​in.cpp

          QApplication app(argc, argv);
          app.setWindowIcon(QIcon(":/images/your_icon.png"));
          

          ma​​inwindow.cpp(如果你有的话,放到你的插槽中)

          void MainWindow::on_aboutAction_triggered()
          {
              QMessageBox::about(0, "window title", "<a href='http://www.jeffersonpalheta.com'>jeffersonpalheta.com</a>");
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-02-25
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-06-04
            相关资源
            最近更新 更多