虽然我能够从QTableWidget的QLabel的linkActivated侦听器成功实现与方法的连接,但是尽管文档指出该链接是可获取的,但我仍无法弄清楚如何通过该方法传递链接。
linkActivated(const QString&link)
我不知道如何在Python中获取“&link”数据。我尝试通过链接的地方有三个问号(???)。
def test(i = 1)
qtbl = QtWidgets.QTableWidget(self.scrollAreaWidgetContents_2)
qtbl.setGeometry(QtCore.QRect(0, 0, 870, 30))
qtbl.setObjectName("qtbl%s" % i )
widget = QtWidgets.QWidget()
widgetText = QtWidgets.QLabel("<a href=\"www.foo.com\"><font color=\"#F2F299\">foo</font></a><a href=\"www.foo.com\"><font color=\"#F299F2\">bar</font></a>")
widgetLayout = QtWidgets.QHBoxLayout()
widgetLayout.addWidget(widgetText)
widgetLayout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
widget.setLayout(widgetLayout)
widgetText.linkActivated.connect(lambda ix, sf = self, lk = ??? : linkListener(sf, lk))
qtbl.setCellWidget(0, 0, widget)
def linkListener(self, link):
print(link)
设计类:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(896, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.scrDocumentTables = QtWidgets.QScrollArea(self.centralwidget)
self.scrDocumentTables.setGeometry(QtCore.QRect(10, 10, 871, 541))
self.scrDocumentTables.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrDocumentTables.setWidgetResizable(False)
self.scrDocumentTables.setObjectName("scrDocumentTables")
self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 869, 539))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.scrDocumentTables.setWidget(self.scrollAreaWidgetContents_2)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 896, 17))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
我意识到这可能是一个新问题,但是如何获取“&link”数据?