2014-09-13 65 views
0

我在使用PySide(Python版本3.2.5)在QLabel中顯示功能超鏈接到網頁的功能超鏈接。從這個帖子c++ - Making QLabel behave like a hyperlink - Stack Overflow閱讀最upvoted答案,我的印象是,這將工作:使用PySide鏈接到QLabel中的網頁

from PySide.QtCore import Qt 
from PySide.QtGui import QApplication, QLabel 

app = QApplication([]) 
window = QLabel() 
window.setText("<a href=\"http://stackoverflow.com/\" />Stack Overflow</a>") 
window.setTextFormat(Qt.RichText) 
window.setTextInteractionFlags(Qt.TextBrowserInteraction) 
window.setOpenExternalLinks(True) 
window.show() 
app.exec_() 

遺憾的是,文本不顯示爲一個鏈接。任何人都可以請我指出正確的方向?

+0

是的;不知道這是怎麼發生的,我以爲我只是複製粘貼標籤...對不起,這個打擾你。 – user1919235 2014-09-16 00:00:38

回答

3

你的鏈接被破壞,修復它應該沒問題;

from PyQt4.QtGui import QApplication, QLabel 

myQApplication = QApplication([]) 
myQLabel = QLabel() 
myQLabel.setText('''<a href='http://stackoverflow.com'>stackoverflow</a>''') 
myQLabel.setOpenExternalLinks(True) 
myQLabel.show() 
myQApplication.exec_()