I started to write my first PyQT application (PyQT is used only to handle GUI), and it seems, that good toolchain is: QtDesigner to generate .ui s and handle resources and some IDE, that can set QtDesigner to edit those. I use Eclipse, cause it is highly customisable.
You can compile your .qrc and .ui by demand by doing somewhat like this at application start, or at setup, or any other time:
os.system("pyrcc4.exe -o ui/images_rc.py ui/images/images.qrc")
uic.compileUiDir(appDir + '/ui', True)
and then using generated classes this way:
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, owner):
QtGui.QMainWindow.__init__(self)
# 'Ui_MyMainWindow' is the class, that was generated by uic,
# naming convention is: 'Ui_' plus the name of root widget in designer
self.ui = Ui_MyMainWindow()
self.ui.setupUi(self)
or you can load .ui directly when container inits:
QtGui.QMainWindow.__init__(self)
self.ui = None
uic.loadUi('MyMainWindowUI.ui', self.ui)
#now you have the instance of Ui_MyMainWindow in self.ui too, as above
note, that I have added UI suffix to .ui file's name, it was done to avoid name intersection , cause name of .py file, generated by uic, is not class name starting with 'Ui_', but just root widget's one.
And another one note: at the end of generated file uic places 'import %.qrc name%_rc' (by default is import images_rc) string, so you must aware this when using pyrcc4.
The whole approach is flexible enough, it takes all dummy ui coding work from you; but you still can do some fine tuning in MyMainWindow.ui attribute, where the instance of Ui_MyMainWindow lays; and it avoids unneeded inheritance. Personally, I make _connectSlots and _initIntefrace methods in MyMainWindow to do some work designer cannot.
Still I have to note that writing interface code by yourself is good approach, cause the code, generated by uic, is UGLY. I prefer to load .ui in place by loadUi() because of this :) And if you have a lot of custom PyQT controls, it is so booooring to bring them into QtDesigner..
Best Answer
Don't blame yourself, I think Qt's Layout logic is a bit confusing when you start to deal with. If I understood well what you are saying, the contents of the form are not "connected", i.e. not resizing and not restricted by the form size, right? I think you have missed to set a "centralWidget layout". Try the following:
Open your form by double clicking it in QtCreator (I don't use the QtDesigner frequently but I think the editor layout is almost the same on both tools).
Go to the top-right window (the one having 2 columns "Object-Class") and Right-Click with your mouse at the root object (e.g. MainWindow).
A context menu will appear. Click on "Lay out" (last menu item) and select "Layout Vertically" or "Layout Horizontally"
These actions will create a layout on the centralWidget object. If you select the "centralWidget" in the "Object-Class" window you can then view & change the layout properties in the (bottom-right) Property-Value window; they are the last properties in list.
More important, after you add a layout in your centralWidget, the contents of your form should be resizing along & limited by your form's size.
I hope this helps.