How to add icon without a text into QListWidget?
-
wrote on 1 Feb 2016, 12:24 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
-
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
-
wrote on 2 Feb 2016, 06:31 last edited by
Are you using stylsheets? Did you use listWidget->setViewMode(QListView::IconMode); ? Can you provide sample code of the problem?
-
Are you using stylsheets? Did you use listWidget->setViewMode(QListView::IconMode); ? Can you provide sample code of the problem?
wrote on 2 Feb 2016, 07:17 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 -
wrote on 2 Feb 2016, 23:32 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.
-
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.
wrote on 3 Feb 2016, 09:21 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 -
wrote on 3 Feb 2016, 09:36 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 ? -
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 ? -
wrote on 3 Feb 2016, 10:55 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
2/10