PyQt5 – How to make text center align of the editable ComboBox
In this article we will see how we can center align the text of combo box. By default the combo box text is left align and combo box don’t have any alignment method of its own.
In order to center align the text we have to do the following –
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
1. Create a combo box
2. Make combo box editable (optional)
3. Make line edit object from combo box
4. Center align the line edit
Syntax : For creating line edit and setting its alignment
# getting the line edit of combo box line_edit = self.combo_box.lineEdit() # setting line edit alignment to the center line_edit.setAlignment(Qt.AlignCenter)
Below is the implementation –