Reputation: 3479
I am adding a list of strings to a QList Widget like this:
myList.addItems( [ 'item1' , 'item2' , 'item3' ] )
By default the list aligns these to the left but I want to get them in the center of the list.
Any Ideas?
Upvotes: 0
Views: 8285
Reputation: 4510
If you create a QListWidgetItem()
you can call its setTextAlignment()
method and pass Qt.AlignHCenter
:
item_text_list = [ 'item1' , 'item2' , 'item3' ]
for item_text in item_text_list:
item = QListWidgetItem(item_text)
item.setTextAlignment(Qt.AlignHCenter)
myList.addItem(item)
Docs: QListWidgetItem, Qt.AlignmentFlag
Upvotes: 5