[PyQt] How to open QWhatsThis hyperlinks in an external browser?

Darren Dale dsdale24 at gmail.com
Fri Dec 5 15:06:53 GMT 2014


For many widgets in a GUI I'm developing, I would like to add What's This
documentation that contain links to online Sphinx-based documentation. In
Designer, I can add whatsThis documentation with hyperlinks, but clicking
the link in the resulting GUI doesn't do anything. Based on the
documentation for QWhatsThis (
http://pyqt.sourceforge.net/Docs/PyQt4/qwhatsthis.html), and some searching
online (http://qt-project.org/forums/viewthread/34565), my understanding is
that I would need to reimplement the `event` method for each widget,
perhaps along the lines of:

    def event(self, e):
        try:
            href = e.href()
            import webbrowser
            webbrowser.open_new_tab(href)
        except AttributeError:
            pass
        super(self.__class__, self).event(e)

On the other hand, I'm using Designer and uic.loadUi, so the prospect of
subclassing numerous widgets is... I don't know how I would do it. And the
prospect of rewriting the entire GUI programmatically to support this
rather obvious use case makes me suspect I'm just doing it wrong.

Is it possible to plug in to PyQt's uic/loadUi routines to define the
`event` method for every widget that gets instantiated? Or is there another
approach I have overlooked?

Thanks,
Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141205/fa2b2e3c/attachment.html>


More information about the PyQt mailing list