Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Icon margin in QListWidget
Forum Update on Monday, May 27th 2025

Icon margin in QListWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlistwidgetqiconmargin
5 Posts 3 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alextekeuf
    wrote on 21 Aug 2016, 12:49 last edited by
    #1

    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!

    R 1 Reply Last reply 22 Aug 2016, 06:01
    0
    • A alextekeuf
      21 Aug 2016, 12:49

      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!

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 22 Aug 2016, 06:01 last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      A 1 Reply Last reply 22 Aug 2016, 10:09
      1
      • R raven-worx
        22 Aug 2016, 06:01

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

        A Offline
        A Offline
        alextekeuf
        wrote on 22 Aug 2016, 10:09 last edited by
        #3

        @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... ^^

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Aug 2016, 21:58 last edited by
          #4

          Hi and welcome to devnet,

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

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 24 Aug 2016, 18:05
          0
          • S SGaist
            22 Aug 2016, 21:58

            Hi and welcome to devnet,

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

            Hope it helps

            A Offline
            A Offline
            alextekeuf
            wrote on 24 Aug 2016, 18:05 last edited by
            #5

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

            1 Reply Last reply
            0

            1/5

            21 Aug 2016, 12:49

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved