Re: [PyQt] question about size hints

2010-05-03 Thread Yao Ko
On Sun, May 2, 2010 at 5:05 AM, Darren Dale dsdal...@gmail.com wrote:
 On Sun, May 2, 2010 at 1:51 AM, Yao Ko ko...@raptr.com wrote:
 On Sat, May 1, 2010 at 5:47 AM, Darren Dale dsdal...@gmail.com wrote:
 Please excuse me for bumping. Does anyone have a suggestion?

 On Sun, Apr 18, 2010 at 12:42 PM, Darren Dale dsdal...@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?

Looks like the problem is not with the Test widget, but with the
initial size of MainWindow.  What if you set the initial size of
MainWindow to whatever is defined in Test.sizeHint() in
MainWindow.__init__() ?  This way, the MainWindow will start at the
size needed to hold the Test widget at full size, but it will still
allow the Test widget to be smaller if user so desires.

Yao
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] question about size hints

2010-05-02 Thread Darren Dale
On Sun, May 2, 2010 at 1:51 AM, Yao Ko ko...@raptr.com wrote:
 On Sat, May 1, 2010 at 5:47 AM, Darren Dale dsdal...@gmail.com wrote:
 Please excuse me for bumping. Does anyone have a suggestion?

 On Sun, Apr 18, 2010 at 12:42 PM, Darren Dale dsdal...@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_())

 Have you tried to set the size policy to:

 
 ...
 class Test(QtGui.QWidget):
 ...
       self.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                                  QtGui.QSizePolicy.MinimumExpanding)
 ...
 

 The Test widget will have the minimum size specified by the sizeHint,
 and yet the MainWindow can still grow.

Thank you for the suggestion. I actually had tried that, but it is
unfortunately not an acceptable solution because I need to allow the
user to make the size smaller than the original specification. The
exact use case is defining a plot canvas in matplotlib.

Darren
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] question about size hints

2010-05-01 Thread Yao Ko
Have you tried to set the size policy to:


...
class Test(QtGui.QWidget):
...
   self.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
  QtGui.QSizePolicy.MinimumExpanding)
...


The Test widget will have the minimum size specified by the sizeHint,
and yet the MainWindow can still grow.

Yao

On Sat, May 1, 2010 at 5:47 AM, Darren Dale dsdal...@gmail.com wrote:
 Please excuse me for bumping. Does anyone have a suggestion?

 On Sun, Apr 18, 2010 at 12:42 PM, Darren Dale dsdal...@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_())

 ___
 PyQt mailing list    p...@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] question about size hints

2010-04-18 Thread Darren Dale
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_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt