[PyQt] faster alternative to QHeaderView's resizeToContents?

David Douard david.douard at logilab.fr
Tue May 12 08:10:04 BST 2009


On Saturday 09 May 2009 09:28:16 Edwin Marshall wrote:
>  I have a QTableView that displays the contents of a model with over 3000
> rows, each with 11 columns. I'd like to the original size of these columns
> to be no larger than the content within them, but setting their
> resizeMode's to QHeaderView.resizeToContents causes the tremendous slow
> downs (where originally the data would load in two seconds, using this mode
> causes the data to be loaded after about a minute and a half). Is there
> some faster alternative?
>
> I'm thinking of calculating the width by using the length of the largest
> item in the column, but that would require me to know how large in pixels
> each character is.
>
> Any suggestions?  

This can be done reimplementing the sizeHintForColumn method of a QTableView. 
You should create your own QTableView based class and reimplement this method 
the "smart" way. See Qt doc for more details on this method.




-- 
David Douard                        LOGILAB, Paris (France), +33 1 45 32 03 12
Formations Python, Numpy, Debian :  http://www.logilab.fr/formations
Développement logiciel sur mesure : http://www.logilab.fr/services
Informatique scientifique :         http://www.logilab.fr/science



More information about the PyQt mailing list