Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Which Widget is used with the ItemDelegate?
I make a thcatt(messenger) software and I have reached the stage of viewing the message with emoji and I don't know how to do it, here is an image as an example of a conversation:
so @SGaist offered me to use the QItemDelegate, since I didn't know how to do it so @mrjj gave me a link to follow a training on the QItemDelegate and I finished the training well but it doesn't really help me to solve my problem because I don't know from the image posted above where the view is? what model used? to have a result like the one of whatsapp posted in the image above
Thank you for your help in advance
VRonin last edited by
use the QItemDelegate
The class is now deprecated, you should use
I don't know from the image posted above where the view is
the view is what determines how items are laid out, in your image it's a simple
QListViewas all the items are placed one below the other
what model used?
Whatever you want. the model is what holds your strings of chat plus some more metatdata (sender name, date and time of the message, if it was received by the other party or not).
As always I suggest you use
QAbstractItemModelinterface (i.e. declare your model as something like
QAbstractItemModel* model = new QStandardItemModel;). This lets you use the convenience of that model and also always allow you to use any other model in the future changing just 1 line of code.
to have a result like the one of whatsapp posted in the image above
Welcome to hell. You need to reimplement
QStyledItemDelegate::paint. Anything beyond this point is just untested brainstorming:
You can use
QTextLayoutto help you figure out the size of the bubble, paint it and paint the text finally you have to figure out size, position and paint of the time and the tickmarks.
QFontMetricsshould help there
JonB last edited by
Yes thank you very much @VRonin's for your answers as @jonB said it, I have to read it little by little while doing exercises to understand well but if you also have tutorials on QStyledItemDelegate::paint you can give me it because it will also help me
VRonin last edited by
if you also have tutorials on QStyledItemDelegate::paint
There's http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html but it's nowhere near the level of complexity required to layout that bubble
Thanks a lot @VRonin's for the link but I still leave the topic open because in case of blocking I'll just come back here and post my problem to get your help