[PyQt] Resize columns in QTreeViewv

Gionata Boccalini gion at ngi.it
Wed Dec 1 17:22:52 GMT 2010

Wow!! Wonderful!! I wasn't expecting you answer any more!! Thanks for 
you effort!!!
I didn't know about QtGui.QHeaderView.ResizeToContents. Very interesting.
I've read all of yous optimization and I (obviously) agree with you!!
(Just keep in mind that I was building the first Model/View PyQt 
program... so it isn't and won't be perfect!!)
Only a small doubt on the last fix: isn't too expensive or slow to 
recreate a QFileSystemModel at every signal??
Thank you again!!

Gionata Boccalini

Il 01/12/2010 15:00, Hans Meine ha scritto:
> Hi again!
> Op den Dunnersdag 25 November 2010 Klock 21:15:19 hett Gionata Boccalini
> schreven:
>> Ok, don't worry, I absolutely don't want to waste your time!! But what
>> do you mean with
>>> In
>>> general, your code could (and should) be much more concise.
> OK, I had a look again, your code is not much too complex actually.
> Anyhow, there's potential for optimization IMHO:
> - [duplicate/complex code] remove all QTimer and resizeColumnToContents stuff,
> instead use self.__fileView.header().setResizeMode(0,
> QtGui.QHeaderView.ResizeToContents) *
> - for the minimal example for this list, the updateSelection() stuff is
> unnecessary (the smaller the example, the more likely you'll get answers)
> - [consistency] rename __treeView to __dirView
> - [simplicity] instead of connecting to clicked/expanded on the left, what
> about currentChanged?
> - [duplicate code] in any case, don't setup the filemodel's root in __init__,
> but make sure that the connected signals are emitted - in my case, I would
> call setCurrentIndex - in order to let updateFiles() to the job
> - [duplicate code] setup the treeviews with your visual preferences only once
> - maybe disable expansion in the __fileView (and decoration)
> Attached you find a refactored version of your example.
> Then, it is easy to solve your problem by just re-creating the model in every
> updateFiles() step.  I am attaching that, too.
> * I just realized that manual resizing might still be desirable.  Anyhow, the
> timer solution looks quite hacky to my eyes.
> HTH,
>    Hans
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101201/eea0b867/attachment.html>

More information about the PyQt mailing list