PyQt5 Tutorials
About Lesson

In this Python PyQt5 lesson we want to learn about Python PyQt5 QColorDialog & QFontDialog, the QColorDialog class provides a dialog widget for specifying colors. the color dialog’s function is to allow users to choose colors. For example, you might use this in a drawing program to allow the user to set the brush color. the QFontDialog class provides a dialog widget for selecting a font. a font dialog is created through one of the static getFont() functions.

 

 

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

 

 

This is the design.

Qt Designer QColorDialog Design
Qt Designer QColorDialog Design

 

 

 

After completing the design you need to save the .ui file, iam going to name it colord.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() signal with the method that we want to connect.

 

 

You can see that we have also added our two methods, because we want to use these methods in the QPushButton clicked signal. the first method is for changing the color of textedit, we just get the color from QColorDialog and we set the color to the textedit. the second method is for changing font size of the text, and we do the same task, we get the font and set the font for the text.

 

 

 

 

Run the complete code and this is the result.

PyQt5 ColorDialog - Working with QColorDialog & QFontDialog in PyQt
PyQt5 ColorDialog – Working with QColorDialog & QFontDialog in PyQt