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. How to add icon without a text into QListWidget?

How to add icon without a text into QListWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
listwidgeticonno text
10 Posts 3 Posters 7.9k 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.
  • I Offline
    I Offline
    IL
    wrote on 1 Feb 2016, 12:24 last edited by
    #1

    I want to display icon in QListWidget without a text. I set the text to empty string and to size 1. When I select theicon I see an empty square below the icon on the text place.
    How can I get rid of this empty space?

    IL

    T 1 Reply Last reply 1 Feb 2016, 12:43
    0
    • I IL
      1 Feb 2016, 12:24

      I want to display icon in QListWidget without a text. I set the text to empty string and to size 1. When I select theicon I see an empty square below the icon on the text place.
      How can I get rid of this empty space?

      IL

      T Offline
      T Offline
      the_
      wrote on 1 Feb 2016, 12:43 last edited by
      #2

      @IL
      What happens if you only set the icon?

      QListWidgetItem *i;
      i->setIcon(youricon);
      

      -- No support in PM --

      I 1 Reply Last reply 1 Feb 2016, 12:52
      0
      • T the_
        1 Feb 2016, 12:43

        @IL
        What happens if you only set the icon?

        QListWidgetItem *i;
        i->setIcon(youricon);
        
        I Offline
        I Offline
        IL
        wrote on 1 Feb 2016, 12:52 last edited by
        #3

        @the_
        Same same!

        1 Reply Last reply
        0
        • E Offline
          E Offline
          elveatles
          wrote on 2 Feb 2016, 06:31 last edited by
          #4

          Are you using stylsheets? Did you use listWidget->setViewMode(QListView::IconMode); ? Can you provide sample code of the problem?

          I 1 Reply Last reply 2 Feb 2016, 07:17
          0
          • E elveatles
            2 Feb 2016, 06:31

            Are you using stylsheets? Did you use listWidget->setViewMode(QListView::IconMode); ? Can you provide sample code of the problem?

            I Offline
            I Offline
            IL
            wrote on 2 Feb 2016, 07:17 last edited by
            #5

            @elveatles
            Hi,
            Yes I do using style-sheets, and I am not familiar with a way that style-sheets can resolve this issue.
            Icon mode set the text beneath the icon while list-mode set the text beside the icon.
            In both cases I have the same problem.
            I am using QtCreator, creating ListWidget and add items, my code is very basic.
            I can provide code from the ui_mainwindow.h if you point me to something specific.

            Thanks,
            IL

            1 Reply Last reply
            0
            • E Offline
              E Offline
              elveatles
              wrote on 2 Feb 2016, 23:32 last edited by
              #6

              Stylesheets can cause this kind of problem if you are using padding or margin. If you try to remove the stylesheet and create your QListWidgetItems the way "the_" suggested, it should work. If not there must be something I'm not thinking of.

              I 1 Reply Last reply 3 Feb 2016, 09:21
              0
              • E elveatles
                2 Feb 2016, 23:32

                Stylesheets can cause this kind of problem if you are using padding or margin. If you try to remove the stylesheet and create your QListWidgetItems the way "the_" suggested, it should work. If not there must be something I'm not thinking of.

                I Offline
                I Offline
                IL
                wrote on 3 Feb 2016, 09:21 last edited by
                #7

                @elveatles
                Hi and thanks,
                I have removed the style-sheet and create the item with icon only but it still save place for the text.
                I am a bit confused, I don't find any solution for that, something that looks trivial seems to be an issue.
                I will be very happy to know that someone has a solution for that.

                Thanks again,
                IL

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  the_
                  wrote on 3 Feb 2016, 09:36 last edited by
                  #8

                  Just another (maybe crazy and/or stupid) idea...
                  Why not set a custom widget for the QListWidgetItem that looks as you expect it to look like instead of putting an icon to the QListWidgetItem ?

                  -- No support in PM --

                  I 1 Reply Last reply 3 Feb 2016, 10:46
                  0
                  • T the_
                    3 Feb 2016, 09:36

                    Just another (maybe crazy and/or stupid) idea...
                    Why not set a custom widget for the QListWidgetItem that looks as you expect it to look like instead of putting an icon to the QListWidgetItem ?

                    I Offline
                    I Offline
                    IL
                    wrote on 3 Feb 2016, 10:46 last edited by
                    #9

                    @the_
                    What do you mean by saying custom widget?

                    T 1 Reply Last reply 3 Feb 2016, 10:55
                    0
                    • I IL
                      3 Feb 2016, 10:46

                      @the_
                      What do you mean by saying custom widget?

                      T Offline
                      T Offline
                      the_
                      wrote on 3 Feb 2016, 10:55 last edited by
                      #10

                      @IL
                      you can add a widget to an item. So just create a for example frame that contains your icon and add it to the list item.

                      QListWidget *list = new QListWidget(this);
                      //...
                      QFrame *custom = new QFrame;
                      //add whatever you need to the frame
                      QListWidgetItem *i = new QListWidgetItem;
                      list->addItem(i);
                      list->setWidgetItem(i,custom);
                      

                      I used this for a list where each item needed several buttons to get for example detailed information about the item or delete the item from the list with one click

                      -- No support in PM --

                      1 Reply Last reply
                      0

                      4/10

                      2 Feb 2016, 06:31

                      • Login

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