PyQt question

Boudewijn Rempt boudewijn at tryllian.com
Tue Sep 18 04:40:16 EDT 2001


Janos Blazi wrote:

> #
> # hello1.py
> #
> import sys
> from qt import *
> 
> app=QApplication(sys.argv)
> 
> box=QVBox()
> box.resize(200,100)
> quit=QPushButton("Quit", box)
> #quit.setFont(QFont("Times", 18, QFont.Bold))
> quit.connect(quit,SIGNAL('pressed()'),app,SLOT('quit()'))
> app.setMainWidget(box)
> box.show()
> app.exec_loop()
> 
> Now the problem is that they say in the tutorial:
> "The button no longer fills the entire widget. Instead, it gets a
> "natural" size. This is because there is now a new top-level widget, which
> uses layout management to set a good size and position for the button."
> 
> But when I start the program the button is as wide as the entire widget
> and even resizing it does not help. Can anybody tell me, why?
> 

This is quite the expected behaviour. Notices how the height of the button
is now the default button height, instead of as hight as the window. It's 
the property of the QVBox layout manager to resize the button.

The following code will give you a fixed size button:
#
# hello1.py
#
import sys
from qt import *

app=QApplication(sys.argv)

box=QWidget()
box.resize(200,100)
quit=QPushButton("Quit", box)
quit.connect(quit,SIGNAL('pressed()'),app,SLOT('quit()'))
app.setMainWidget(box)
box.show()
app.exec_loop()

That's because the QWidget object, which is now the main widget, doesn't
do layout management at all.

But remember that you probably want layout management. Nothing is so 
user-hostile as a window that cannot be resized.
-- 
Boudewijn | http://www.valdyas.org



More information about the Python-list mailing list