We will continue to develop the Qt theme - mainly becuase it is a versatile interface - and it is the only real GUI option available under Linux.
At this point I am assuming that
- Qt 5.2.1 is installed
- PyQt5 is installed
Design a screen
Normal Qt operation here.
When you are finished then save the UI test.ui say for this example.
Generate the Python Code
A small utility now pyuic5 to run it type
``bash pyuic5 -x test.ui test.py
The -x just adds the extra "glue" so that you can run the output like ```bash python test.py
It is easy to get a display running - however you can not add any extra functionality to this class - as the code will be overwritten in any further modifications to the screen.
This is a perfect example of keeping your UI and the code seperate (an Interface almost).
Build your Interface
In this example we will assuming your Interface is called Ui_Form (A standard Name) - and that you saved this ui as display.ui
I use a custom makefile to build this
display.py : display.ui pyuic5 -x display.ui -o display.py
Add an Implementation class
The original class display.py you should not touch at all... instead create a new file called display_implement.py (You can call it what you want - but you probably should keep their names somewhat aligned).
in this file put the following code
PyQt5 import QtCore, QtGui, QtWidgets from display import Ui_Form class display_implement(Ui_Form): def __init__(self,*args,**kwargs): super(display_implement, self).__init__(*args, **kwargs) f __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_())
Now to run the app do the following command
The display should show normally.
Add More to the Display
In the Qt Designed, add a new widget (say another button).
- Save the UI
- make (to generate the base UI class)
And test by
You should see the new widget in the inheritied class.