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.
  • ILI Offline
    ILI Offline
    IL
    wrote on 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

    the_T 1 Reply Last reply
    0
    • ILI IL

      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

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @IL
      What happens if you only set the icon?

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

      -- No support in PM --

      ILI 1 Reply Last reply
      0
      • the_T the_

        @IL
        What happens if you only set the icon?

        QListWidgetItem *i;
        i->setIcon(youricon);
        
        ILI Offline
        ILI Offline
        IL
        wrote on last edited by
        #3

        @the_
        Same same!

        1 Reply Last reply
        0
        • E Offline
          E Offline
          elveatles
          wrote on last edited by
          #4

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

          ILI 1 Reply Last reply
          0
          • E elveatles

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

            ILI Offline
            ILI Offline
            IL
            wrote on 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 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.

              ILI 1 Reply Last reply
              0
              • E elveatles

                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.

                ILI Offline
                ILI Offline
                IL
                wrote on 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
                • the_T Offline
                  the_T Offline
                  the_
                  wrote on 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 --

                  ILI 1 Reply Last reply
                  0
                  • the_T the_

                    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 ?

                    ILI Offline
                    ILI Offline
                    IL
                    wrote on last edited by
                    #9

                    @the_
                    What do you mean by saying custom widget?

                    the_T 1 Reply Last reply
                    0
                    • ILI IL

                      @the_
                      What do you mean by saying custom widget?

                      the_T Offline
                      the_T Offline
                      the_
                      wrote on 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

                      • Login

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