Is "About Qt" dialog HTML or text content available in Qt5 API?
-
This public static method shows a dialog with Qt version and licensing information:
- void QMessageBox::aboutQt (
QWidget* parent, const QString& title = QString());
Within our Qt application, we need to get our hands on the HTML (or at least text) string displayed in that dialog. Is there a way to do this?
Aside: We really do need what I mentioned above. But short of that, it would be good if the content of the "About Qt" dialog was selectable and copyable. (Currently, it apparently isn't).
We're using Qt 5.5.1 on Windows with Visual Studio 2010 SP1.
- void QMessageBox::aboutQt (
-
This text is not exposed by any public API. There's also no direct programmatic way to get a pointer to the message box (apart from some ugly tricks with top level windows list). If you want to you can copy the text from the sources and show however you like.
The message box uses default text interaction flags which depend on the style. If you want a message box with selectable text you can roll your own and set Qt::TextSelectableByMouse flag on it. -
We have a requirement to provide information about all of our 3rd party libraries in a copyable form. (A read-only QTextEdit, with basic HTML formatting). That is, so that it can be selected, copied and pasted (e.g. into an e-mail message). We don't need to change anything in the About Qt text, as such.
This image shows just the top portion of such a document (in a read-only QTextEdit widget). Notice that, for now, the Qt information can't be included in the document. Instead, we can show the Qt information only with a button (see, at bottom).
-
HI
You can just grab it from the qmessagebox.cppvoid QMessageBox::aboutQt(QWidget *parent, const QString &title) { QString translatedTextAboutQtCaption; translatedTextAboutQtCaption = QMessageBox::tr( "<h3>About Qt</h3>" "<p>This program uses Qt version %1.</p>" ).arg(QLatin1String(QT_VERSION_STR)); QString translatedTextAboutQtText; translatedTextAboutQtText = QMessageBox::tr( "<p>Qt is a C++ toolkit for cross-platform application " "development.</p>" "<p>Qt provides single-source portability across all major desktop " "operating systems. It is also available for embedded Linux and other " "embedded and mobile operating systems.</p>" "<p>Qt is available under three different licensing options designed " "to accommodate the needs of our various users.</p>" "<p>Qt licensed under our commercial license agreement is appropriate " "for development of proprietary/commercial software where you do not " "want to share any source code with third parties or otherwise cannot " "comply with the terms of the GNU LGPL version 3 or GNU LGPL version 2.1.</p>" "<p>Qt licensed under the GNU LGPL version 3 is appropriate for the " "development of Qt applications provided you can comply with the terms " "and conditions of the GNU LGPL version 3.</p>" "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the " "development of Qt applications provided you can comply with the terms " "and conditions of the GNU LGPL version 2.1.</p>" "<p>Please see <a href=\"http://%2/\">%2</a> " "for an overview of Qt licensing.</p>" "<p>Copyright (C) %1 The Qt Company Ltd and other " "contributors.</p>" "<p>Qt and the Qt logo are trademarks of The Qt Company Ltd.</p>" "<p>Qt is The Qt Company Ltd product developed as an open source " "project. See <a href=\"http://%3/\">%3</a> for more information.</p>" ).arg(QLatin1String("2015"), QLatin1String("qt.io/licensing"), QLatin1String("qt.io")); QMessageBox *msgBox = new QMessageBox(parent); msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title); msgBox->setText(translatedTextAboutQtCaption); msgBox->setInformativeText(translatedTextAboutQtText); QPixmap pm(QLatin1String(":/trolltech/qmessagebox/images/qtlogo-64.png"));
-
Thanks, that's what we'll do. If nothing is added to Qt in future versions to support this, we'll just have to manually grab this text each time we upgrade to a new version of Qt.
There might also be some use in having this "About Qt" content at a permanent URL on a public Qt website, distinct for each version (or perhaps with a visible "GET" argument in the URL with the QT_VERSION_STR / qVersion() text).
It might also be good to have the text in the About Qt dialog selectable (copyable) -- but read-only, of course.
-
@Phil_W
Well its the first time I ever saw anyone ask for it so unless you open report and vote for it,
it's unlikely it will change in newer versions.Also, it should possible to grab from code but it will fiddle with internal
objects and might break anyway on next upgrade so maybe just taking the lines
is the best solution. -
Sorry for replying on such an old thread, but I'm currently facing a similar challenge. I am fine with the text of the
QMessageBox::aboutQt()
, but I would like to remove the hyperlinks. I got the requirement that it should not be possible to open a web browser using the GUI application. Is there anything I can do to deactivate the URLs? Do I really have to copy the text from the source of Qt and create my own dialog in order to get rid of the clickable links? -
@FlorianWolters Another alternative would be disabling
QDesktopServices
entirely by compiling Qt yourself and definingQT_NO_DESKTOPSERVICES
for it.If you can't do that you can also add a url handler to QDesktopServices doing nothing:
class DummyUrlHandler : public QObject { Q_OBJECT public slots: void handleUrl(const QUrl &) { } }; // at the start of your application DummyUrlHandler handler; QDesktopServices::setUrlHandler("http", &handler, "handleUrl"); QDesktopServices::setUrlHandler("https", &handler, "handleUrl"); // add other schemes susceptible to open your browser
-
@GrecKo Thank you very much. That is a much cleaner solution and much more secure. I wrote a small class that also deals with unregistration in a RAII way today. Works like a charm.