[PyQt] question about size hints

Darren Dale dsdale24 at gmail.com
Sat May 1 13:47:12 BST 2010


Please excuse me for bumping. Does anyone have a suggestion?

On Sun, Apr 18, 2010 at 12:42 PM, Darren Dale <dsdale24 at gmail.com> wrote:
> I have a question about size hints that can be illustrated with the
> simple example below. If I create my Test widget so it returns a size
> hint of (200,100), it is rendered with a size of 200, 100. If I create
> Test so it is 100x70, it is rendered to be 200x100. If I create test
> to be 1000x700, it is rendered to be 853x533 (my screen resolution is
> 1280x800). If I set the size policy to be fixed, then the central
> widget size policy is respected, but I can't resize the window. How
> can I make m respect the size hint of the central widget, but still
> maintain the ability to resize the window?
>
> Thank you,
> Darren
>
>
> import sys
> from PyQt4 import QtCore, QtGui
>
> class Test(QtGui.QWidget):
>
>    def __init__(self, width, height):
>        QtGui.QWidget.__init__(self)
>        #self.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
>        print 'Central widget should have width=%d, height=%d' %(width, height)
>        self._width = width
>        self._height = height
>
>    def sizeHint(self):
>        return QtCore.QSize(self._width, self._height)
>
> app = QtGui.QApplication([])
> m = QtGui.QMainWindow()
> c = Test(1000, 700)
> m.setCentralWidget(c)
> m.show()
> s = c.size()
> print 'but central widget has width=%d, height=%d'% (s.width(), s.height())
> sys.exit(app.exec_())
>


More information about the PyQt mailing list