(trying out the syntax highlighting. nice!) |
|||
| Line 19: | Line 19: | ||
</code> | </code> | ||
Of course you will need to make a ui file called demo.ui for this to work. | Of course you will need to make a ui file called demo.ui for this to work. | ||
| + | |||
| + | ==Connecting Buttons From Dynamically loaded .ui File== | ||
| + | |||
| + | ===loaddialog.py=== | ||
| + | <code python> | ||
| + | import sys | ||
| + | from PyQt4 import QtGui | ||
| + | from PyQt4 import uic | ||
| + | |||
| + | # the class has to have the same base class as your UI | ||
| + | class DemoImpl(QtGui.QDialog): | ||
| + | def __init__(self, *args): | ||
| + | QtGui.QWidget.__init__(self, *args) | ||
| + | # just pass self | ||
| + | uic.loadUi("demo.ui", self) | ||
| + | #for some reason this seems to be called twice | ||
| + | def on_button1_clicked(self): | ||
| + | print "You Clicked the button!" | ||
| + | |||
| + | def on_pushButton_2_clicked(self): | ||
| + | print "You Clicked the button2!" | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | app = QtGui.QApplication(sys.argv) | ||
| + | widget = DemoImpl() | ||
| + | widget.show() | ||
| + | app.exec_() | ||
| + | |||
| + | </code> | ||
Contents |
I am just putting some stuff here right now, because you have such nice color coding in your wiki. Maybe I'll turn it into a tutorial if I figure out what I am doing.
I found this snippet here (french). I don't know if this is the right way to do it, but it seems to work.
import sys
from PyQt4 import QtGui, uic
app = QtGui.QApplication(sys.argv) widget = uic.loadUi("demo.ui") widget.show()
app.exec_() Of course you will need to make a ui file called demo.ui for this to work.
import sys
from PyQt4 import QtGui
from PyQt4 import uic
class DemoImpl(QtGui.QDialog):
def __init__(self, *args):
QtGui.QWidget.__init__(self, *args)
# just pass self uic.loadUi("demo.ui", self)
#for some reason this seems to be called twice
def on_button1_clicked(self):
print "You Clicked the button!"
def on_pushButton_2_clicked(self):
print "You Clicked the button2!"
app = QtGui.QApplication(sys.argv)
widget = DemoImpl()
widget.show()
app.exec_()