Question

I have a listwidget where the user can add icon files. I show these files inside my listwidget as icon-items (my listwidget’s viewmode is IconMode). Each of the items has as text its basename (e.g. if the path to the image is /home/alex/Pictures/mypic.jpg, then the text of the corresponding item will be mypic.jpg).

I want to strictly show on each line a specific number of items. The problem exists when there are images with basename short and others with very long. Then, the listwidget, because I’ve set

ui->listWidget->setUniformItemSizes(true);

chooses to add one item per line, only because the basename of specific items are very long. What I want to do is to crop each basename (the listwidget already does it to specific items but not to items with very long text) if it is too long and have a strict number of items per line.

Each of my items has

item->setTextAlignment(Qt::AlignCenter);

Here are some pictures indicating the problem:

How I want it to be, and how it is when the basenames are quite short and don’t differ very much from each other:

What the problem is, when I have both long and short basenames:

I want the long basenames to be shorted, as well. I don’t really get why the listwidget doesn’t crop the long basenames while it does it to some much shorter ones.

Was it helpful?

Solution

QListWidgetItem setSizeHint() for the win :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top