Search code examples
c++qtstylesheet

How to create something close to a chat bubble using Qt StyleSheets


I went through the stylesheet docs, but I am still not sure what/where I should be looking for.

I have a QListBox that I want to style is such a way that each entry in the listbox appears in a chat bubble. The bubble should look something like this or fairly close to it:

Tailed message bubble


Solution

  • If you are indeed using QListView/QListWidget you can try something like this:

    setStyleSheet("QListView::item{border-width:25px 25px 50px 25px; border-image: url(:/img/bubble.png) 25 25 50 25 stretch;}");
    

    Read this to learn more about how border-image works.

    Another option is to subclass QStyledItemDelegate and draw your bubble in its paint() method.