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
QtWS25 Last Chance

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.
  • alextekeufA Offline
    alextekeufA Offline
    alextekeuf
    wrote on 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!

    raven-worxR 1 Reply Last reply
    0
    • alextekeufA alextekeuf

      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!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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

      alextekeufA 1 Reply Last reply
      1
      • raven-worxR raven-worx

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

        alextekeufA Offline
        alextekeufA Offline
        alextekeuf
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

          alextekeufA 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

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

            Hope it helps

            alextekeufA Offline
            alextekeufA Offline
            alextekeuf
            wrote on 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

            • Login

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