PDA

View Full Version : QListView Icons with uniform sizes



psih128
22nd November 2009, 14:25
Hi

I implemented my own model and I'm trying to dislay it with QListView in the Icon mode. I want. The models' DecorationData returns pixmap which is not of the same size for all the items. some are larger, some smaller.

Now I want them to be laid out on a grid with the same space per item, so I set uniformItemSizes to true.. this resizes all the items to the smallest item size (see the screenshot)

The I tries setting grid Size to the size of the biggest item, but I cant find a good way to calculate the size for the text below the item, it's sometime quite long. so sometimes the text would get trimmed..

The i tried to make all the pixmaps returned by the model of the same size by scaling them:

return pixmap.scaled(size, Qt::KeepAspectRatio);
but nothing changed - the size of the smallest icon did not change...

So basically I tried a few approaches to layout differently sized icons with text on a QListView...Could you please suggest me a solution?

Thanks

aamer4yu
23rd November 2009, 05:30
How are you implementing decoration role for the model ?
You can return uniform size pixmaps from the data function. Since you are using model, you have more control over things.

psih128
23rd November 2009, 11:25
yes I use the DecorationRole and that piece of code I had in the initial post is what I return for this role. As you can see Im trying to scale them to the same size but it does not actually scale the pixmaps properly. for example if the pixmap size is 12x80 and I scale it to 80x80 using that code, it still remains 12x80