[Qt-interest] set QListWidget's sizeHint() to fit contents

Paul Miller paul at fxtech.com
Thu Jun 18 14:39:23 CEST 2009


Serge wrote:
> Hi,
> 
> I have QListWidget's descendant with constant 3 rows. I need to define 
> its size so that it would not need vertical scroll bar and at the same 
> time there would be no free space under last row. In other word i need 
> to fit height of QListWidget to height of its contents. How can i detect 
> height of contents in code of sizeHint() procedure?

I use code like this (on my abstract item views):

int rows = view->model()->rowCount();
int rowSize = view->sizeHintForRow(0);
int height = rows * rowSize;
int frameWidth = view->frameWidth();
view->setFixedHeight(height + frameWidth * 2);
	

-- 
Paul Miller | paul at fxtech.com | www.fxtech.com | Got Tivo?




More information about the Qt-interest-old mailing list