PDA

View Full Version : [PyQt] displaying icon and text in one QListWidgetItem on QListWidget



naoyamakino
14th July 2009, 23:03
I am currently implementing an instant messenger called Pendulim (http://code.google.com/p/pendulim/) written in Python using PyQt4,
and I am having a trouble with displaying emoticons and text in one line on
chat window.

I am using QListWidget to display conversations and each line as
QListWidgetItem. the trouble is that i cannot add or append QListWidgetItem,
so I can't combine emoticon and string.

this is a chatwindow class.
http://code.google.com/p/pendulim/source/browse/trunk/pendulim/current_build/interface/ChatWindow.py

for example:

item = QtGui.QListWidgetItem(self.convoWindow)
emoticon = QtGui.QListWidgetItem(self.convoWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(path), QtGui.QIcon.Normal, QtGui.QIcon.Off)
emoticon.setIcon(icon)
item.setText(some_string)
#here i would like to combine item and emoticon so that I can display it in
one line

Is there any way to display icon and string in one QListWidgetItem? or is
there any alternative way to meet the need?
I would very appreciate if you could give me any kind of help.
thank you for consideration.

Best regards

Naoya Makino

wysota
15th July 2009, 09:58
What is the effect you obtain? The code you have shown looks correct and should work fine.

naoyamakino
15th July 2009, 15:53
hi wysota, your reply on another post solved a problem. the effect I was getting here was that text and emoticons are in the different lines. the code works fine, but I needed to show emoticons and text in the same line. so i decided to use QTextedit instead.

for a reference, here is the another post that has a solution to display emoticon and text showing in one line (not using QListWidgetItem)

How to display image on QPlainTextEdit (http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-display-image-on-qplaintextedit-22495-post109495.html#post109495)

regards