[PyQt] Timing problem with resizing of main window

John Posner jjposner at optimum.net
Sun Jun 27 17:59:00 BST 2010


On 6/24/2010 2:32 AM, Vincent Vande Vyvre wrote:
> Le 23/06/10 21:37, John Posner a écrit :

>> In the program below, the main window's central widget is a QFrame
>> that *always* contains a control panel (CtrlPanel, subclass of
>> QFrame). Pressing the "Create work panel" button inserts another
>> QFrame above the CtrlPanel, causing the main window to grow
>> vertically. Pressing the "Remove work panel" button removes the work
>> panel, which *should* cause the main window to shrink vertically to
>> its original size.
>>
>> But the main window does not shrink automatically (using CHOICE = 0 in
>> line 74). Method MainWin.fix_size() should force the main window to
>> shrink, but simply invoking this method after removing the work panel
>> (CHOICE = 1) does not have the desired effect. The only thing that
>> works for me is using a QTimer to invoke MainWin.fix_size() after a
>> short delay (CHOICE = 2).
>>
>> Note: I also tried invoking update() on various objects -- no luck there.
>>
>> Can anyone provide some insight into what's going on and/or what I'm
>> doing wrong?
>>
>> Environment: Python 2.6.5; QtCore.qVersion() == 4.5.3
>>
>> Many thanks,
>> John
>>
>>
>> #-------------------------
      <snip>
>> #-------------------------
>> _______________________________________________
>> PyQt mailing list PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
> Hi,
>
> Change this def :
>
> def fix_size(self):
> """change window size after removing work panel"""
> self.ctrlpanel.resize(*self.ctrlpanel.smallsize)
> C.QCoreApplication.processEvents()
> self.resize(*self.ctrlpanel.smallsize)
>
> and :
>
> elif CHOICE == 1:
> # DOES NOT WORK: resize main window immediately
> C.QCoreApplication.processEvents()
> self.mainwin.fix_size()
>
> use CHOICE = 1
> --
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy>
>

Merci bien, Vincent. Using processEvents() works fine in the test 
program I submitted.

But here's an interesting wrinkle: when I change the test program to 
invoke fix_size() via signal/slot instead of a direct call, things work 
fine. The large application from which I abstracted the test program 
uses signal/slot to call fix_size(). When I applied your change to the 
large application, the resizing does not work. Changing from signal/slot 
to a direct call *does* work, so I'm happy now (if still a little confused).

-John



More information about the PyQt mailing list