Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed URL link to QLabel

Clicking QLabel should open a default web browser with URL link specified. It is not happening yet. Why? A second question. Would it be possible to override the default blue color of the Label's font with something else?

enter image description here

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_())
like image 456
alphanumeric Avatar asked Sep 28 '15 21:09

alphanumeric


1 Answers

The styling of the label's contents can be modified using the standard html syntax.

To automatically open external links:

    label.setOpenExternalLinks(True)
like image 152
ekhumoro Avatar answered Sep 19 '22 05:09

ekhumoro