PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about PyQt6 ColorDialog & FontDialog, we will learn that how you can create QColorDialog and QFontDialog in PyQt6.  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 QTextEdit from the widget box
  • Add two QPushButton, make the buttons layout horizontally
  • Make the main window layout vertically 
PyQt6 QColorDialog & QFontDialog
PyQt6 QColorDialog & QFontDialog

 

 

 

After completing the design you need to save the .ui file, iam going to name it ColorD.ui, now convert the file to py file.

 

 

 

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.

PyQt6 ColorDialog & FontDialog
PyQt6 ColorDialog & FontDialog

 

 

 

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