[PyKDE] QWidgetFactory problems

Torsten Marek shlomme at gmx.net
Sun Feb 6 15:26:34 GMT 2005

Hash: SHA1

Eli Yukelzon schrieb:
| Hi there.
| I've picked up a very nice WidgetFactory wrapper from PyQT wiki, and
| been a very happy user so far. But today I've came across a very
| serious (for me) problem with it, and was hoping that someone can shed
| some light over this. Here's the situation:
| I have QMainWindow and I want to catch it's closeEvent (to ask for
| user interaction). When I use pyuic to generate the class, and then
| capture the event - all works just great.
| When I use WidgetFactory to create the window, the event is fired only
| when the signal is emited (i,e when i connect some button to close()
| slot), but not when the event is 'spontanious', i.e. when the 'x'
| button is pressed in window's titlebar.
| I've attached an example of the problem. the ui file, the qt_loader
| which is the WidgetFactory wrapper, and .py file which has both
| versions of code, with, and without WidgetFactory.
| Thanks in advance,
| Eli Yukelzon

Hello Eli,

I think I spotted the problem, I hope my explanation is sufficient.

- - create is called with connector instance
- - ui instance (ui) is loaded
- - attributes are copied over from ui to Connection (but only, if they do not
exist in Connector)
- - for every connection in ui, Qt.connect is setup that in a way so that methods
in Connector (!) are called

Now, if the button is clicked in ui, it calls Connector.close, which itself
calls Connector.closeEvent, which prints out its message.
If the window close button is clicked, ui.close is called, which calls
ui.closeEvent (<- not overridden!).
To solve this problem (in a hackish manner), you would also have to copy over
the overridden event handlers from Connector to ui. Anyway, I'm not convinced
that this is good style. There should be a better solution for run-time
generated UI files, but it involves a more sophisticated approach.

Anybody in for good ideas, so I don't have to think too much?


- --
Torsten Marek <shlomme at gmx.net>
ID: A244C858 -- FP: 1902 0002 5DFC 856B F146  894C 7CC5 451E A244 C858
Keyserver: subkeys.pgp.net

Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org


More information about the PyQt mailing list