2010-03-17 77 views
5
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>"); 

此代碼創建,我想有兩個例外關於消息框,一個GUI消息框:的「關於」對使用Qt

1)我想更改消息中的圖標帶有aaa.png文件的框

2)我希望鏈接可點擊。它看起來像超鏈接(它是藍色和下劃線),但鼠標點擊不起作用

任何想法?

回答

2

我認爲你應該爲你的widget創建一個自定義QWidget。通過這種方式,你可以把所有你想要的小部件。例如,您可以使用openExternalLinks屬性將QLabel放置爲可點擊鏈接。

要在QWidget上顯示自定義圖像,此example可能會有所幫助。

1

對於圖標,您只需設置應用程序圖標即可。事情是這樣的:

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

作爲使可點擊的鏈接,我不認爲它可以直接與QMessageBox::about API來完成。

+0

確定,可能是你能告訴我,在一般情況下,我們如何可以在裏面創建一個超鏈接文本的小部件? – Narek 2010-03-17 20:00:47

1
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(); 
0

對於未來的參考,文檔指出,爲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,以使其相應採取行動。

0

的main.cpp

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

mainwindow.cpp(到您的插槽,如果你有一個)

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