[PyQt] Examples for uic module in PyQt
Shriramana Sharma
samjnaa at gmail.com
Fri Apr 13 15:35:20 BST 2007
I would like to contribute the following examples for the PyQt
documentation. They relate to using the uic module.
-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-
When using PyQt4.uic.loadUi, the following examples apply:
In the direct approach:
-------------------------------------------------------------------------
#! /usr/bin/env python
import sys
from PyQt4 import QtGui, uic
app = QtGui.QApplication(sys.argv)
window = uic.loadUi("imagedialog.ui")
window.show()
sys.exit(app.exec_())
-------------------------------------------------------------------------
In the single inheritance approach:
-------------------------------------------------------------------------
#! /usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui, uic
class ImageDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = uic.loadUi("imagedialog.ui")
self.ui.show()
# Make some local modifications.
self.ui.colorDepthCombo.addItem("2 colors (1 bit per pixel)")
# Connect up the buttons.
self.connect(self.ui.okButton, QtCore.SIGNAL("clicked()"),
self, QtCore.SLOT("accept()"))
self.connect(self.ui.cancelButton, QtCore.SIGNAL("clicked()"),
self, QtCore.SLOT("reject()"))
app = QtGui.QApplication(sys.argv)
window = ImageDialog()
sys.exit(app.exec_())
-------------------------------------------------------------------------
-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-
I hope these are useful. I never tried the multiple inheritance approach
but I presume it would work out similar to the single inheritance
approach. Please also take this as a request to improve the PyQt uic
module documentation. Thank you.
Shriramana Sharma.
More information about the PyQt
mailing list