Issue
I want to create a hyperlink of (file_path ) using python that will point to the file in operating system. I am able to get the path of the file. How can I create a hyperlink of this path and store in a variable. I want to display this in the QtWidgets as link where user can click and open the file stored in windows OS.
file_path = os.path.join(dir_path, FileName)
self.documents.setItem(0, 0, QtWidgets.QTableWidgetItem(file_path))
Solution
You can use QLabel
with html content to create clickable link.
from PyQt5 import QtWidgets, QtCore
import os
if __name__ == "__main__":
app = QtWidgets.QApplication([])
path = os.environ["USERPROFILE"]
text = "click me"
label = QtWidgets.QLabel('<a href="{}">{}</a>'.format(path, text))
label.show()
label.linkActivated.connect(os.startfile)
app.exec()
Answered By - mugiseyebrows
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.