PDA

View Full Version : QListView Text Elide Like QListWidget



Kel Solaar
11th May 2010, 21:08
Hello,

I would like to know how the QListWidget setup in iconMode is doing to elide the text under the icon in order to do the same with a QListView.

I have setup a QListView and a QListWidget, a QStandardItemModel is used to feed the QListView.

Here a screen of the widgets, the top one being the QListView, the bottom one being the QListWidget :

http://kelsolaar.hdrlabs.com/sIBL_GUI/Support/Pictures/sIBL_GUI_ListViewVsListWidget.jpg

as you can see the QListWidget is eliding the texts nicely.

Now here is a test using the setUniformItemSizes method of the QListView :

http://kelsolaar.hdrlabs.com/sIBL_GUI/Support/Pictures/sIBL_GUI_ListViewVsListWidget_UniformSize.jpg

Better but not really perfect.

KS

norobro
12th May 2010, 00:54
Take a look at QListView::setGridSize() (http://doc.qt.nokia.com/4.6/qlistview.html#gridSize-prop)

aamer4yu
12th May 2010, 11:57
Also look QAbstractItemView::setTextElideMode

Kel Solaar
12th May 2010, 19:53
Hello,

Thanks for the replies !

Unfortunatly the QAbstractItemView::setTextElideMode didn't helped, I think the size of the delegate is calculated with some dependency on the text data width, changing the icon size was'nt affecting my listview the way I want.
The problem with the QListView::setGridSize() is that it's killing spacing around the items producing something like this :

http://kelsolaar.hdrlabs.com/sIBL_GUI/Support/Pictures/sIBL_GUI_ListViewVsListWidget_GridSize.jpg

Ayway I got something I'm satisfied with by setting a new size hint everytime the icon size change :



for i in range( self._model.rowCount() ) :
iblSetStandardItemItem = self._model.item( i )
iblSetStandardItemItem.setSizeHint( QSize( value, value + 16 ) )


"16" being the margin I add to display the text.

KS

norobro
12th May 2010, 20:21
Glad that you solved your problem. I don't mean to be a contrarian but by varying the width and/or height in setGridSize() can't you achieve the same result?

Kel Solaar
12th May 2010, 21:35
Yeah It does the trick in an even sexier way ! Dunno why I didn't thought putting a gridSize bigger than my icons width :) Thanks again !

aamer4yu
13th May 2010, 05:44
for i in range( self._model.rowCount() ) :
iblSetStandardItemItem = self._model.item( i )
iblSetStandardItemItem.setSizeHint( QSize( value, value + 16 ) )

From above it seems you are using your own model..
Instead of iterating over all items and setting their size hint, you can return the size hint from model::data function too.