How to Create FontComboBox in Pyside2

In this article i want to show you How to Create FontComboBox in Pyside2, for creating FontComboBox you can use QFontComboBox class in Pyside2. also you can watch more articles on Python GUI Development with Pyside2 in the below links.

 

1: Getting Started With Pyside2 | Qt For Python 

2: Pyside2 GUI Creating First Window 

3: Pyside2 GUI Creating Window Icon

4: Pyside2 GUI How To Create Icon Modes

5: Pyside2 GUI How To Create Tooltip

6: Pyside2 GUI QPushButton With Signal And Slot

7: Pyside2 GUI Making Center The Window 

8: Python GUI How To Create AboutBox

9: Python GUI How to Create Digital Clock in Pyside2

10: How To Create StatusBar In Pyside2 

11: Pyside2 Creating QProgressBar

12: Pyside2 Layout Managment with QHBoxLayout

13: Pyside2 GridLayout Example

14: Pyside2 Creating Calendar 

15: Pyside2 Create CheckBox

 

What is QFontComboBox ?

The combobox is populated with an alphabetized list of font family names, such as Arial, Helvetica, and Times New Roman. Family names are displayed using the actual font when possible. For fonts such as Symbol, where the name is not representable in the font itself, a sample of the font is displayed next to the family name.

 

 

So now this is the complete code for How to Create FontComboBox in Pyside2

 

 

So at the top first we have  imported our required classed from pyside2, after that we have created our window class that inherits from QWidget, and we have added the requirement of our window in that class, also we have called our setIcon() and setFontBox() methods in our class.

 

 

This method is for window icon, make sure that you have added an icon in your working directory

 

OK now this is the method that we are going to create our FontComboBox

in the above code first we have created a QVBoxLayout, and after that we have created QFontComboBox object.

also we have set the filters for our FontComboBox, there are different filters that you can use.

 

Constant Value Description
QFontComboBox.AllFonts 0 Show all fonts
QFontComboBox.ScalableFonts 0x1 Show scalable fonts
QFontComboBox.NonScalableFonts 0x2 Show non scalable fonts
QFontComboBox.MonospacedFonts 0x4 Show monospaced fonts
QFontComboBox.ProportionalFonts 0x8 Show proportional fonts

 

 

Also every Pyside2 application must create an application object. The sys.argv parameter is a list of arguments from a command line.

Python scripts can be run from the shell. It is a way how we can control the startup of our scripts

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.

The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead

 

 

So now run the complete code and this will be the result

How to Create FontComboBox in Pyside2
How to Create FontComboBox in Pyside2

 

 

Also you can watch the complete video for this article

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×