0

How to change format and color of some items in qlistwidget?

d={"apple":12, "orange": 5} for k in d: self.qlistwiget.additem(k) # how can change items of qlistwidget to yellow?

13th Mar 2017, 7:20 PM
hamid
hamid - avatar
1 Answer
0
You can use the color attributes for aqlistwidgetitem setBackgroundColor setTextColor using your example to set the text colour white and background black: d={"apple":12, "orange": 5} for k in d: # create a new listwidgetitem new_item = qListWidgetItem(k) # create a q colour using hex (check docs for other options like rgb) q_text_color = qColor("#FFFFFF") q_back_color = qColor("#000000") new_item.setTextColor(q_text_color) new_item.setBackgroundColor(q_back_color) self.qlistwiget.additem(new_item) You could simplify this a little with: d={"apple":12, "orange": 5} for k in d: # create a new listwidgetitem new_item = qListWidgetItem(k) # create a q colour using hex (check docs for other options like rgb and names like 'red') new_item.setTextColor(qColor("#FFFFFF")) new_item.setBackgroundColor(qColor("#000000") ) self.qlistwiget.additem(new_item)
14th Mar 2017, 2:25 AM
Elric Hindy
Elric Hindy - avatar