[PyQt] QTreeWidget and fixed column widths on window resize

Chris M chris.pm at gmail.com
Thu Jul 31 21:37:04 BST 2008


Not sure if there is a 'cleaner' solution but overriding the event is
fairly simple, for example;

class MyTreeWidget(QTreeWidget):
    def __init__(self, parent = None):
        super(MyTreeWidget, self).__init__(parent)

    def resizeEvent(self, event):
        width = event.size().width()
        self.setColumnWidth(1, 100)
        self.setColumnWidth(2, width - 100)

Also means you can make your common customizations within the __init__
method to keep your main code cleaner.

2008/7/31 Tyler Distad <tyler.distad at gmail.com>:
> I am attempting to create a QTreeWidget containing two columns. The
> rightmost column is to remain at a fixed width, no matter how large
> the window itself grows. The leftmost column is to grow in the normal
> manner. (Picture the playlist columns in your favorite music player,
> and you probably have exactly what I'm attempting.)
>
> However, I am completely unable to restrict the growth of the
> right-hand component. The only suggestion I can find online deals with
> overloading resizeEvent(), which seems ludicrously complicated for
> something like this. Is there any sort of a clean solution?
>
> Tyler Distad
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


More information about the PyQt mailing list