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?



  • 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:
    0_1541700001616_Capture.PNG

    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 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 QStandardItemModel through the QAbstractItemModel interface (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 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
    You may find it a lot to take in, but @VRonin's post above is really useful to read through carefully and work through bit by bit.



  • 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



  • @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


Log in to reply