Important: Please read the Qt Code of Conduct -

Icon margin in QListWidget

  • Hi everybody,

    I'm trying to add margins to the icon of each element of a QListWidget and it doesn't work...

    I tried to modify the stylesheet of my QListWidget like this :

    QlistWidgetItem::icon {
        margin-right: 70px;

    But nothing happens :(
    I didn't found anything about it in my searches...

    I'd prefer to do it from the Qt Designer (from the QListWidget stylesheet?) but any answer would help me a lot!

  • Moderators

    Because QListWidgetItem isn't a widget and stylesheets can only be applied on widgets.
    See this.

  • @raven-worx

    Thanks for your answer. Now I understand why it didn't work, as QListWidgetItem is not a widget...

    Do you think it's possible to do it in another way?
    Directly modify the QIcon of each QListWidgetItem in the C++ code?

    I have to admit that I don't know how to simply modifiy graphical objects without layouts...
    But I'm surprised to be the first who doesn't want these icons that close to the text which is pretty ugly... ^^

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can implement your own QStyledItemDelegate to paint things where you want them.

    Hope it helps

  • @SGaist

    Thank you for your answer, I'm gonna try in this way.

    If it works, i'll post it here because I'm sure it could be helpfull for someones... I'm actually surprise to see that it's not implemented within the QListWidget class!