SlideShare a Scribd company logo
1 of 12
Download to read offline
4
Design a GUI using QT Designer of PyQT4
 QT Designer
 Create widget
 Using Filter: Label
 Drag and drop to the new widget
 Adjust size
 Press Ctrl+R to view what you created
 Filter: Line Edit
 Drag and drop to widget
 Filter: Button
 Drag and drop a push button
5
Signals and slots: Components communication
 Move from Edit Widget mode to Edit Signal/Slots
mode
 Or press F4
 Use F3 to go back to Edit Widget mode
 Next, we want the Push button to affect the Hello
world label
 Click and drug a line from the
button to the label
6
Signals and slots: Components communication
 Select the result of the “IF-THEN” statement
 Select clicked() and Next clear()
 F3 to go back to Edit Widget mode
 Change the name
of the button to show Clear
 Ctrl+R
 Try it!
7
Properties of the widget
8
Signals and slots: Components communication
 We want the textbox to edit the label
 F4 to go to Edit Signal/Slots mode
 IF textChanged(QString) THEN setText (QString)
9
Signals and slots: Components communication
 Ctrl+R
 Type to the text box
 IF push button THEN clicked()->clear()
10
Edit widget
 F3
 Select Push button and Text box
 Lay out Horizontally
 Select 3 items
 Lay Out Vertically
11
Edit widget
 Make the widget responsive
 Select Form: QWidget from Object Inspector
 Lay Out in a Grid
 Ctrl+R
 Resize widget size
12
Save project and convert it to python script
 Save it as a ui file
 qt_hello.ui (like XML schema)
 Convert ui file to python code
 Open a command line
 C:Python27Libsite-packagesPyQt4
 pyuic4 -o OutFile_ui.py InFile.ui
 Pyuic4.bat file is in
 C:Python27Libsite-packagesPyQt4
13
Execute your script using python
 Open qt_hello.py using an editor
 Add import sys after from PyQt4 import QtCore, QtGui
 At the end of your code add:
def main():
app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()
ui = Ui_Form()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
System-specific parameters
and functions
Define a new function called main()
without any parameters
The QDialog class is the base class of
dialog windows.
A dialog window is a top-level window
mostly used for short-term tasks and
brief communications with the user.
Initializes the window system and
constructs an application object
with argc command line arguments
in argv. sys. argv is a list in Python,
which contains the command-line
arguments passed to the script.Form created
from QT Designer
When the Python interpreter reads a source
file, it executes all of the code found in it.
14
Execute your script using python
 Open cmd (command shell)
 python py_hello.py
 In a lab pc you have to write the full path of python from
the folder that you save the py_hello.py file, e.g.
 C:Python27python py_hello.py

More Related Content

Similar to GUI_using_QT_Designer_PyQT4

Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
 
PT1420 Modules in Flowchart and Visual Basic .docx
PT1420 Modules in Flowchart and Visual Basic             .docxPT1420 Modules in Flowchart and Visual Basic             .docx
PT1420 Modules in Flowchart and Visual Basic .docxamrit47
 
Chapter 08
Chapter 08Chapter 08
Chapter 08llmeade
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...bhargavi804095
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5Akhil Mittal
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
PYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptx
PYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptxPYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptx
PYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptxTrangNguyenThiHuyen6
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxAnasYunusa
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesSami Mut
 
TYPO3 create a CKEditor plugin
TYPO3 create a CKEditor pluginTYPO3 create a CKEditor plugin
TYPO3 create a CKEditor pluginFrans Saris
 
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor pluginTYPO3 CertiFUNcation
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Tutorial_Python1.pdf
Tutorial_Python1.pdfTutorial_Python1.pdf
Tutorial_Python1.pdfMuzamilFaiz
 

Similar to GUI_using_QT_Designer_PyQT4 (20)

PyQt.pptx
PyQt.pptxPyQt.pptx
PyQt.pptx
 
Chapter - 6.pptx
Chapter - 6.pptxChapter - 6.pptx
Chapter - 6.pptx
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
 
PT1420 Modules in Flowchart and Visual Basic .docx
PT1420 Modules in Flowchart and Visual Basic             .docxPT1420 Modules in Flowchart and Visual Basic             .docx
PT1420 Modules in Flowchart and Visual Basic .docx
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
lec 9.pptx
lec 9.pptxlec 9.pptx
lec 9.pptx
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
PYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptx
PYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptxPYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptx
PYTHONNANGCAO_1.GUI.Creating the GUI Form and Adding Widgets.pptx
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
COM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptxCOM 211 PRESENTATION.pptx
COM 211 PRESENTATION.pptx
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
TYPO3 create a CKEditor plugin
TYPO3 create a CKEditor pluginTYPO3 create a CKEditor plugin
TYPO3 create a CKEditor plugin
 
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Tutorial_Python1.pdf
Tutorial_Python1.pdfTutorial_Python1.pdf
Tutorial_Python1.pdf
 

GUI_using_QT_Designer_PyQT4

  • 1.
  • 2. 4 Design a GUI using QT Designer of PyQT4  QT Designer  Create widget  Using Filter: Label  Drag and drop to the new widget  Adjust size  Press Ctrl+R to view what you created  Filter: Line Edit  Drag and drop to widget  Filter: Button  Drag and drop a push button
  • 3. 5 Signals and slots: Components communication  Move from Edit Widget mode to Edit Signal/Slots mode  Or press F4  Use F3 to go back to Edit Widget mode  Next, we want the Push button to affect the Hello world label  Click and drug a line from the button to the label
  • 4. 6 Signals and slots: Components communication  Select the result of the “IF-THEN” statement  Select clicked() and Next clear()  F3 to go back to Edit Widget mode  Change the name of the button to show Clear  Ctrl+R  Try it!
  • 6. 8 Signals and slots: Components communication  We want the textbox to edit the label  F4 to go to Edit Signal/Slots mode  IF textChanged(QString) THEN setText (QString)
  • 7. 9 Signals and slots: Components communication  Ctrl+R  Type to the text box  IF push button THEN clicked()->clear()
  • 8. 10 Edit widget  F3  Select Push button and Text box  Lay out Horizontally  Select 3 items  Lay Out Vertically
  • 9. 11 Edit widget  Make the widget responsive  Select Form: QWidget from Object Inspector  Lay Out in a Grid  Ctrl+R  Resize widget size
  • 10. 12 Save project and convert it to python script  Save it as a ui file  qt_hello.ui (like XML schema)  Convert ui file to python code  Open a command line  C:Python27Libsite-packagesPyQt4  pyuic4 -o OutFile_ui.py InFile.ui  Pyuic4.bat file is in  C:Python27Libsite-packagesPyQt4
  • 11. 13 Execute your script using python  Open qt_hello.py using an editor  Add import sys after from PyQt4 import QtCore, QtGui  At the end of your code add: def main(): app = QtGui.QApplication(sys.argv) window = QtGui.QDialog() ui = Ui_Form() ui.setupUi(window) window.show() sys.exit(app.exec_()) if __name__ == "__main__": main() System-specific parameters and functions Define a new function called main() without any parameters The QDialog class is the base class of dialog windows. A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user. Initializes the window system and constructs an application object with argc command line arguments in argv. sys. argv is a list in Python, which contains the command-line arguments passed to the script.Form created from QT Designer When the Python interpreter reads a source file, it executes all of the code found in it.
  • 12. 14 Execute your script using python  Open cmd (command shell)  python py_hello.py  In a lab pc you have to write the full path of python from the folder that you save the py_hello.py file, e.g.  C:Python27python py_hello.py