2012-04-05 71 views
2

我已經將textFormat設置爲Qt::RichText,但鏈接仍然是不可點擊的。QMessageBox內部有鏈接,無法點擊

QMessageBox msgBox(this); 
msgBox.setWindowTitle(QApplication::applicationName() 
         + " $VER " + QApplication::applicationVersion()); 
msgBox.setTextFormat(Qt::RichText); //this is what makes the links clickable 
msgBox.setText("<a href=\"google.com\">Google</a>"); 
msgBox.setStandardButtons(QMessageBox::Ok); 
msgBox.exec(); 

任何解決方案?它被證實不適用於Qt 4.7。

+1

這個怎麼樣:''Google「'? – Anonymous 2012-04-05 12:31:43

+0

@Anonymous也不工作..我真的不知道爲什麼,它應該在Linux上調用xdg-open – daisy 2012-04-05 13:01:04

+0

您是否在控制檯中獲得任何調試輸出?同樣的事情發生在一個簡單的獨立代碼上嗎?是否有桌面環境的文件開啓器應用程序('gvfs-open','kde-open'等)? – Anonymous 2012-04-13 10:57:53

回答

2

它正在我的Qt 4.7.4下工作,儘管我不得不修改你的HTML。小例子:

#include <QApplication> 
#include <QMessageBox> 

int main(int argc, char *argv[]) 
{ 
    QApplication app(argc, argv); 

    QMessageBox msgBox; 
    msgBox.setTextFormat(Qt::RichText); //this is what makes the links clickable 
    msgBox.setText("<a href='http://google.com/'>Google</a>"); 
    msgBox.setStandardButtons(QMessageBox::Ok); 
    msgBox.exec(); 
    return app.exec(); 
} 

如果我用這一個,瀏覽器選項卡是越來越開放,下面的消息在我的控制檯結束:

Created new window in existing browser session. 

如果我用你的msgBox.setText我得到錯誤:

gvfs-open: file:///tmp/b/google.com: error opening location: Error stating file '/tmp/b/google.com': No such file or directory 
+0

你在Linux上嗎?我忘記添加該標籤... – daisy 2012-04-05 13:00:33

+0

您是否嘗試過提供的最小示例?你能點擊鏈接嗎?有什麼事情發生?任何寫入控制檯的內容(例如'在現有瀏覽器會話中創建新窗口.')? – Anonymous 2012-04-05 13:09:30