Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to add icon without a text into QListWidget?

    General and Desktop
    listwidget icon no text
    3
    10
    6684
    Loading More Posts
    • 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.
    • IL
      IL last edited by

      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_ 1 Reply Last reply Reply Quote 0
      • the_
        the_ @IL last edited by

        @IL
        What happens if you only set the icon?

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

        -- No support in PM --

        IL 1 Reply Last reply Reply Quote 0
        • IL
          IL @the_ last edited by

          @the_
          Same same!

          1 Reply Last reply Reply Quote 0
          • E
            elveatles last edited by

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

            IL 1 Reply Last reply Reply Quote 0
            • IL
              IL @elveatles last edited by

              @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 Reply Quote 0
              • E
                elveatles last edited by

                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.

                IL 1 Reply Last reply Reply Quote 0
                • IL
                  IL @elveatles last edited by

                  @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 Reply Quote 0
                  • the_
                    the_ last edited by

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

                    IL 1 Reply Last reply Reply Quote 0
                    • IL
                      IL @the_ last edited by

                      @the_
                      What do you mean by saying custom widget?

                      the_ 1 Reply Last reply Reply Quote 0
                      • the_
                        the_ @IL last edited by

                        @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 Reply Quote 0
                        • First post
                          Last post