?print-pdf
' Created for
Qt (pronounced "cute") framework is a widget toolkit for creating GUIs as well as cross-platform applications that run on various software and hardware platforms such as Linux, Windows, macOS, Android or embedded systems with little or no change in the underlying codebase while still being a native application with native capabilities and speed.[Reference: Qt @wikipediq]
# on activated virtual environment:
pip install PyQt5
# check install info:
pip show PyQt5
sudo apt install python3-pyqt5
pyqt_test.py
file and run it.
import sys
from PyQt5.QtWidgets import QApplication,QWidget,QLabel,QPushButton
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle('PyQt5 App Works')
window.setGeometry(100, 100, 500, 500)
window.show()
sys.exit(app.exec_())
You should see a window like:
Qt Designer normally ships as a part of Qt Creator. This is Qt's official editor and lets you do a lot more than just graphically design user interfaces. It is a full-fledged and very powerful C++ IDE. But For PyQT development you don't need the whole Qt Creator (which is huge).
You can install only the Qt Designer in two ways:
# make sure you're on activated virtual environment:
pip install pyqt5-tools
# check install info:
pip show pyqt5-tools
sudo apt-get install qttools5-dev-tools
sudo apt-get install qttools5-dev
pyuic5
is included in the pyqt5-tools
, so you do not need to install it. Just use it.
pyuic5 helloWorld.ui -o helloWorld.py
You need to perform next steps only if you don't have PyQt5
, PyQt5-sip
and pyqt5-tools
packages
File => Settings => Tools => External Tools
click the +
buttonFile => Settings => Tools => External Tools
click the +
buttonui
file with QtDesigner
import sys
from PyQt5.QtWidgets import (
QApplication, QMainWindow
)
from helloWorld import Ui_MainWindow
class Window(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec())
Template | Form Type | Widgets | Base Class |
---|---|---|---|
Dialog with Buttons Bottom | Dialog | OK and Cancel buttons laid out horizontally on the bottom-right corner | QDialog |
Dialog with Buttons Right | Dialog | OK and Cancel buttons laid out vertically on the top-right corner | QDialog |
Dialog without Buttons | Dialog | No | QDialog |
Main Window | Main Window | A menu bar at the top and a status bar at the bottom | QMainWindow |
Widget | Widget | No | QWidget |
The Qt team maintains a thorough documentation, as well as user guides, tutorials, etc. for working wit QtDesigner
my_first_GUI.ui
my_first_GUI.ui
file to python code, using the pyuic5
toolmy_first_GUI_app.py
which will start a Qt App and shows the GUI created by you with QtDesigner.