Course Content
PyQt5 Basics – Installation Process, Qt Designer Intro
In this part we are going to talk about some basics functionalities in PyQt5, we go through installation process, creating QPushButton, Signals and working with Qt Designer.
PyQt5 Tutorials
About Lesson

In this PyQt5 PrinterDialog lesson we want to learn Working with QPrinterDialog in PyQt, also we will learn that how you can create print preview dialog, so the the QPrintDialog class provides a dialog for making the printer’s configuration. using this dialog users can change document-related settings, such as the paper size and orientation, type of print (color or grayscale), range of pages, and number of copies to print, and the QPrintPreviewDialog class provides a dialog for previewing and configuring page layouts for printer output.


Now open your Qt Designer,  you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create Widget window. now we add widgets in Qt Designer.

  • Add a vertical layout at the top 
  • Add a horizontal layout at the bottom 
  • In the VBoxLayout add a QTextEdit
  • In the HBoxLayout add two QPushButton



So this is the design.

PyQt5 Print Dialog
PyQt5 Print Dialog



After completing the design you need to save the .ui file, iam going to name it printd.ui, now copy the file and paste it in the Scripts folder of your Python installation, because we want to convert our ui file in to python file and for converting you need to use pyuic5 module. pyuic5 module is located in the Scripts folder of your Python installation, run this command for converting in your terminal.



And this is the converted code also we have added our clicked() signals with the methods that we want to connect.

You can see that we have added our two methods, we have already connected these methods with the clicked signal of the QPushButton.



This method is for creating of the print dialog. we have created the object of the QPrinter, also we have created the object of QPrintDialog and after that we have executed our dialog.



And these methods are for creating PrintPreveiw Dialog.



Run the complete code and this is the result.

PyQt5 PrinterDialog - Working with QPrinterDialog in PyQt
PyQt5 PrinterDialog – Working with QPrinterDialog in PyQt




And this is the PrintPreview dialog.

Working with QPrinterDialog in PyQt
Working with QPrinterDialog in PyQt
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found