Unsolved Which Widget is used with the ItemDelegate?
-
Hello everyone,
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
-
use the QItemDelegate
The class is now deprecated, you should use
QStyledItemDelegate
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
QListView
as all the items are placed one below the otherwhat 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 useQStandardItemModel
through theQAbstractItemModel
interface (i.e. declare your model as something likeQAbstractItemModel* 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
QTextLayout
to 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.QFontMetrics
should help there -
-
-
@EL-jos said in Which Widget is used with the ItemDelegate?:
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