Beginner: Simple Output to a Dialog PyQt4

Glen mansonmuni at alexandria.cc
Mon Apr 23 20:54:43 EDT 2007


On Sat, 21 Apr 2007 03:15:00 +0200, David Boddie wrote:

> On Tuesday 17 April 2007 07:42, Glen wrote:

> 
# Just to avoid any misunderstanding: the form is actually stored as XML.
# You can create C++ code with uic or Python code with pyuic4.
Right.  I do remember noticing that when I opened one of the .ui files.

Thanks for the instructions.  I'm tackling signals and slots next.  I'll
be reading your post a few times, I'm sure.  For the time being, just to
get myself off the ground and see some output, I imported my functions
from cnt.py into my main with 'from cnt import cnt'.  Then I passed my
QTextEdit object into my python code and output the contents of my file
with:
f = file("filename", 'r')
for line in f:
	QTxtObj.insertPlainText(line)

Maybe you could point out some problems with doing it this way, but I'm at
the point now where I have to learn how to handle signals and slots.  I'm
setting up an input dialog with several options, such as download a URL,
choose an existing file.

Your information will come in handy.

Glen

>
>> [quoted text muted]
> 
> OK. Ideally, your window will contain a button (or some other control)
> that the user can click to execute the functions.
> 
>> [quoted text muted]
> 
> If, for example, you included a push button (QPushButton) in the form
> you created with Qt Designer, and called it executeButton, you could
> connect its clicked() signal to a function in cnt by including the
> following line after setting up the user interface:
> 
>   window.connect(ui.executeButton, SIGNAL("clicked()"), cnt.myFunction)
> 
> This assumes that your function is called myFunction(), of course.
> However, you wouldn't be able to get the output from this function back
> to the dialog just by using a signal-slot connection like this.
> 
> One way to solve this would be to wrap the function using another
> function or instance that is able to modify the contents of the dialog.
> Another cleaner approach would be to subclass the user interface class
> (Ui_Dialog) and implement a custom slot that can both call the function
> and modify the dialog.
> 
> For example:
> 
> class Dialog(QDialog, Ui_Dialog)
> 
>     def __init__(self, parent = None):
>     
>         QDialog.__init__(self, parent)
>         self.setupUi(self)
> 
>         self.connect(self.executeButton, SIGNAL("clicked()"),
>                      self.callFunction)
> 
>     def callFunction(self):
>     
>         data = cnt.myFunction()
>         # Do something with the data.
> 
> Hope this gets you started,
> 
> David




More information about the Python-list mailing list