Skip to content

Instantly share code, notes, and snippets.

@evandrix
Created March 4, 2013 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandrix/5080117 to your computer and use it in GitHub Desktop.
Save evandrix/5080117 to your computer and use it in GitHub Desktop.
PyQt4 + load pyuic4-generated *.ui -> *.py
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from <REPLACE_BY_PYUI_DESIGN> import <REPLACE_BY_WINDOW_CLASS_IN_PYUI_DESIGN>
class MainWindow(QMainWindow, <REPLACE_BY_WINDOW_CLASS_IN_PYUI_DESIGN>):
# custom slot
def mymethod(self):
self.textFieldExample.setText('Hello World')
self.textFieldExample.clear()
def __init__(self):
QMainWindow.__init__(self)
# set up User Interface (widgets, layout...)
self.setupUi(self)
# custom slots connections
QObject.connect(self.pushButton,SIGNAL("released()"),self.mymethod) # signal/slot connection
# Main entry to program. Sets up the main app and create a new window.
def main(argv):
# create Qt application
app = QApplication(argv,True)
# create main window
wnd = MainWindow() # classname
wnd.show()
# Connect signal for app finish
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
# Start the app up
sys.exit(app.exec_())
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment