<div dir="ltr"><div>Perfect, thank you. I'm doing something along the lines of:<br><br>        temp = WhatsThisUrlLoader()<br>        for k, v in self.__dict__.items():<br>            if isinstance(v, QWidget):<br>                v.installEventFilter(temp)<br><br></div><div>with:<br><br><br></div>class WhatsThisUrlLoader(QObject):<br><br>    def eventFilter(self, e):<br>        if e.type() == QEvent.WhatsThisClicked:<br>            webbrowser.open_new_tab(e.href())<br>        return False<br><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 5, 2014 at 10:27 AM, Florian Bruhin <span dir="ltr"><<a href="mailto:me@the-compiler.org" target="_blank">me@the-compiler.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">* Darren Dale <<a href="mailto:dsdale24@gmail.com">dsdale24@gmail.com</a>> [2014-12-05 10:06:53 -0500]:<br>
<span class="">> For many widgets in a GUI I'm developing, I would like to add What's This<br>
> documentation that contain links to online Sphinx-based documentation. In<br>
> Designer, I can add whatsThis documentation with hyperlinks, but clicking<br>
> the link in the resulting GUI doesn't do anything. Based on the<br>
> documentation for QWhatsThis (<br>
> <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qwhatsthis.html" target="_blank">http://pyqt.sourceforge.net/Docs/PyQt4/qwhatsthis.html</a>), and some searching<br>
> online (<a href="http://qt-project.org/forums/viewthread/34565" target="_blank">http://qt-project.org/forums/viewthread/34565</a>), my understanding is<br>
> that I would need to reimplement the `event` method for each widget,<br>
> perhaps along the lines of:<br>
><br>
>     def event(self, e):<br>
>         try:<br>
>             href = e.href()<br>
>             import webbrowser<br>
>             webbrowser.open_new_tab(href)<br>
>         except AttributeError:<br>
>             pass<br>
>         super(self.__class__, self).event(e)<br>
<br>
</span>You'd also have to check if the event actually is a QWhatsThisEvent<br>
(e.type() == QEvent.WhatsThisClicked).  Then the try/except is<br>
probably unnecessary as well.<br>
<span class=""><br>
> On the other hand, I'm using Designer and uic.loadUi, so the prospect of<br>
> subclassing numerous widgets is... I don't know how I would do it. And the<br>
> prospect of rewriting the entire GUI programmatically to support this<br>
> rather obvious use case makes me suspect I'm just doing it wrong.<br>
><br>
> Is it possible to plug in to PyQt's uic/loadUi routines to define the<br>
> `event` method for every widget that gets instantiated? Or is there another<br>
> approach I have overlooked?<br>
<br>
</span>You could use an event filter[1] on the QApplication to intercept all<br>
WhatsThisClicked events and react on them.<br>
<br>
[1] <a href="http://qt-project.org/doc/qt-4.8/eventsandfilters.html#event-filters" target="_blank">http://qt-project.org/doc/qt-4.8/eventsandfilters.html#event-filters</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Florian<br>
<br>
--<br>
<a href="http://www.the-compiler.org" target="_blank">http://www.the-compiler.org</a> | <a href="mailto:me@the-compiler.org">me@the-compiler.org</a> (Mail/XMPP)<br>
             GPG 0xFD55A072 | <a href="http://the-compiler.org/pubkey.asc" target="_blank">http://the-compiler.org/pubkey.asc</a><br>
         I love long mails! | <a href="http://email.is-not-s.ms/" target="_blank">http://email.is-not-s.ms/</a><br>
</font></span><br>_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br></div>