Skip to content Skip to sidebar Skip to footer

How To Style (rich Text) In Qlistwidgetitem And Qcombobox Items? (pyqt/pyside)

I have found similar questions being asked, but without answers or where the answer is an alternative solution. I need to create a breadcrumb trail in both QComboBoxes and QListWid

Solution 1:

You could use html/css-likes styles, i.e just wrap your text inside tags:

item.setData( QtCore.Qt.UserRole, "<b>{0}</b>".format('data to store for this QListWidgetItem'))

Another option is setting a font-role:

item.setData(0, QFont("myFontFamily",italic=True), Qt.FontRole)

Maybe you'd have to use QFont.setBold() in your case. However, using html-formating might be more flexible at all.

In the case of a combo-box use setItemData():

# use addItem or insertItem (both works)# the number ("0" in this case referss to the item index)
combo.insertItem(0,"yourtext"))
#set at tooltip
combo.setItemData(0,"a tooltip",Qt.ToolTipRole)
# set the Font Color
combo.setItemData(0,QColor("#FF333D"),Qt.BackgroundColorRole)
#set the font
combo.setItemData(0, QtGui.QFont('Verdana', bold=True), Qt.FontRole)

Using style-sheet formating will not work for the Item-Text itself, afaik.

Post a Comment for "How To Style (rich Text) In Qlistwidgetitem And Qcombobox Items? (pyqt/pyside)"