[Eric] How can I use custom slots in Eric4/qtdesigner

Detlev Offenbach detlev at die-offenbachs.de
Wed Mar 23 18:28:16 GMT 2011


On Dienstag, 22. März 2011, Jeroen Eitjes wrote:
> Thanks.
> 
> I would not have been able to figure that out myself. Is this information
> also available in some documentation?
> 
> Jeroen.
> 
> On Tue, Mar 22, 2011 at 6:41 PM, Detlev Offenbach
> 
> <detlev at die-offenbachs.de>wrote:
> > On Dienstag, 22. März 2011, Jeroen Eitjes wrote:
> > > Hi,
> > > 
> > > I am new to Eric4 and I have a problem. I have designed a userinterface
> > 
> > for
> > 
> > > an app in qtdesigner via eric4.
> > > 
> > > I have a button in this design. I am trying to connect the clicked()
> > 
> > signal
> > 
> > > of this button to a custom slot. I want to be able to run some python
> > 
> > code
> > 
> > > when the button is clicked.
> > > So I tried the following:
> > > 
> > > 1. Place the button on the main form (qtdesigner)
> > > 2. Right-click on the form and choose the option "Change Signals/slots"
> > > 3. In the Signal/slots form I click on the + of the Slots to add a
> > > custom slot
> > > 4. I name the custom slot "on_pushRetrieveBackupBrowser_clicked()" and
> > > click OK
> > > 5. I go to the Signal/Slot editor and connect pushRetrieveBackupBrowse
> > > clicked() signal to mainWindow.on_pushRetrieveBackupBrowser_clicked()
> > 
> > Do not do steps 2 to 5.
> > 
> > > 6. I Save the file in qtdesigner and go to Eric4
> > > 7. I choose compile all in Eric4, which works
> > > 8. I choose "Generate Dialog Code" to get a subclass.
> > 
> > This generates a class named after your form prepended by Ui_ (e.g.
> > Ui_MyDialog). Create a class and derive it from the auto generated class
> > and
> > the proper Qt class (e.g. MyDialog(QDialog, Ui_MyDialog)). In the
> > __init__ method call as one of the very first steps self.setupUi(self).
> > All slot of the
> > form 'on_MyButton_clicked()' (and others) get connected automatically.
> > 
> > All these steps can be done from within eric. From the context menu of
> > the project forms viewer select the entry "Generate dialog code ..." and
> > enter/select the appropriate data. Some template code for the selected
> > options
> > will be generated.
> > 
> > > This gives an error
> > > message: "QMainWindow object has no attribute
> > > on_pushRetrieveBackupBrowser_clicked"
> > > 
> > > This is my problem.
> > > 
> > > What am I doing wrong? How can I have code executed when a button is
> > > clicked?
> > > 
> > > Thanks,
> > > 
> > > Jeroen Eitjes.
> > 
> > Detlev
> > --
> > Detlev Offenbach
> > detlev at die-offenbachs.de

The tutorial available via the eric web site does contain the steps. However, 
the manual steps described are not related to eric, that is standard PyQt. 
Just the shortcut via the menu is eric.

Detlev
-- 
Detlev Offenbach
detlev at die-offenbachs.de


More information about the Eric mailing list