[PyQt] Make main window expand when inner widget resized

Giuseppe Corbelli giuseppe.corbelli at copanitalia.com
Thu Jun 12 08:02:14 BST 2014


On 11/06/2014 23:00, Tony Arnold wrote:
> I have a QTableView widget inside a QMainWindow. The table view widget
> has been initialised with:
>
>          self.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
>
> so that the table view widget expands/shrinks as the contents of the
> table expands and shrinks.
>
> This works, however, the main window (which contains the table view
> widget) stays the same size. I'd like it to expand and shrink and for it
> to stay just big enough to contain the table view widget.
>
> I've struggled for days to achieve this without success so far. I've
> also googled this as much as I can. Does anyone have any suggestions?

Never tried this, seems to me an unconfortable behaviour, having the main 
window shrink and expand...

Maybe you can try to reimplement one of the

resizeColumnsToContents
columnResized

methods. One of them should be called whenever the size hint of the content 
changes. You can get the new size and set the size hint for the parent (main 
window). Makes sense?

-- 
             Giuseppe Corbelli
WASP Software Engineer, Copan Italia S.p.A
Phone: +390303666318  Fax: +390302659932
E-mail: giuseppe.corbelli at copanitalia.com


More information about the PyQt mailing list