Search code examples
pythonpyqt5qtablewidget

Pyqt5: Hyperlink in table's cell


I'm trying to insert a hyperlink into a table cell. How can I do this?

what i do:

self.tableWidget.setItem(0, 0, QtWidgets.QTableWidgetItem('<a href="https://google.com">google</a>'))

but it doesn't work


Solution

  • add this to your code:

    self.tableWidget.itemDoubleClicked.connect(self.OpenLink)
    
    def OpenLink(self,item):
        if item.column() == 1:
            webbrowser.open('www.google.com')
    

    you can change it based on your needs like that: item.text() == the text in the cell, item.row() == row number and item.column() == column number.