点击QLabel应该打开指定的URL链接的默认网络浏览器,但目前还未发生。为什么呢? 第二个问题。是否可以将标签字体的默认蓝色改为其他颜色?
class Widget(QtGui.QWidget):
def __init__(self, *args):
QtGui.QWidget.__init__(self, *args)
vLayout=QtGui.QVBoxLayout(self)
self.setLayout(vLayout)
urlLink="<a href=\"http://www.google.com\">'Click this link to go to Google'</a>"
label=QtGui.QLabel(self)
label.setText(urlLink)
vLayout.addWidget(label)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
urlLink=" <a href=\"http://www.google.com\"> <font face=verdana size=12 color=black> 这是一个链接</font> </a>"
- alphanumericsetTextInteractionFlags
必须设置LinksAccessibleByMouse
。https://doc-snapshots.qt.io/qtforpython-5.15/PySide2/QtCore/Qt.html?highlight=textselectablebymouse#PySide2.QtCore.PySide2.QtCore.Qt.TextInteractionFlag - Lorem Ipsum