[PyQt] Defining a custom slot in Designer
David Boddie
david at boddie.org.uk
Sun Jan 18 00:15:15 GMT 2009
On Sat Jan 17 23:52:10 GMT 2009, Henrik Pauli wrote:
> On Saturday 17 January 2009, David Boddie wrote:
> > How did you add the slot to the testclient.ui file?
>
> right-click on MainWindow, Change Signals/Slots, add a Slot.
OK, I overlooked that. :-)
For me, running Qt 4.4.3 and PyQt 4.4.4, using uic.loadUi() to load a
.ui file with a custom slot doesn't cause an exception to be raised, so
maybe there's a problem with the version you're using.
I hadn't really experimented much with the custom slot features, so I
created a simple form with a push button and a custom slot (slot1) and
used the connection editor to connect the button's clicked() signal to
slot1().
In Python I wrote the following code to make the custom slot do something:
UiClass, WidgetClass = loadUiType("/home/david/temp/untitled.ui")
class Widget(UiClass, WidgetClass):
def __init__(self):
WidgetClass.__init__(self)
self.setupUi(self)
def slot1(self):
print "Clicked"
> Yeah, this is what I ended up doing instead -- this way though I don't see
> that connection in Designer (not as if it were a problem, per se, I'm not
> much of a Designer/Glade person anyway (much to the annoyance of my
> coworkers, heheh!)).
Maybe the above technique will make you reconsider. :-)
> > Maybe you can give some more information about what you're trying to do.
>
> Hard. I'm not even sure yet what I'm doing :) Haven't coded in Python and
> Qt in ages, but I needed something that had a CSS-capable HTML display
> embedded, so I dug into it... As a quick idea so I have to mess as little
> with the GUI itself as possible, I'll give out "commands" with a QLineEdit
> and see the communication log in a QTextBrowser, and if there's some HTML
> to be displayed, it goes into the WebKit thing. The command handler was
> the slot I needed, and since I randomly found the Change Signals and Slots
> item in the menu, I thought I'd give it a try :)
Hopefully, the above code should get you started, though you may want to
upgrade PyQt if it turns out that there's a problem with your version of
pyuic4.
David
More information about the PyQt
mailing list