[PyQt] Maximum image size for BoxLayout
David Boddie
david at boddie.org.uk
Sat Feb 21 19:34:25 GMT 2009
On Sat Feb 21 12:46:38 GMT 2009, Deon wrote:
> I'm just starting out with PyQT, so still a lot to learn over here.
>
> I sit with the following layout.
>
> MainLayout = VBox
> VBox Top = Grid
> VBox Bottom = HBox
>
> HBox Left = QList
> HBox Right = QLable
>
>
> I want to know what the maximum size is (in pixles) for HBox Right,
> without expanding the window.
It depends on what you have in the other layouts. Do you want to calculate
an exact value in advance, or do you just want to know the theoretical
maximum size of the label?
> I tried Various solutions, like putting a scrollbox, another vbox, hbox,
> inside HBox Right, but none give me the desired result.
> I tried SizePolicy, SizeHine and maximumSize with various results, but
> none of the gives the dimensions of HBox Right.
How are you trying to obtain the dimensions? Are you experimenting with
Qt Designer?
> The maximum values I recieved so far is 524287 x 524287 pixels, and I
> say without a doubt that my monitor does not support such a high
> resolution. :)
>
> Can anyone nudge me in the right direction here please.
Can you say how you arrived at those values? The theoretical maximum size
of a widget can be much larger than that. See this page for more details:
http://doc.trolltech.com/4.4/qwidget.html#maximumSize-prop
It refers to this definition in the Qt source code:
src/gui/kernel/qwidget.h:1029:#define QWIDGETSIZE_MAX ((1<<24)-1)
> What I'm trying to accomplish is to display an image as large as
> possible, without breaking aspect ratio. The image can be rotated if it
> would meen a bigger display.
If you want to scale it without breaking aspect ratio, but still keep
it completely visible, then you may need something a bit smarter than
QLabel. I'm sure someone will correct me if I misremember anything, but
the QLabel class will ignore the aspect ratio of an image.
If you want to use an alternative class to display the image then this
may do what you want:
class Label(QWidget):
def __init__(self, image, *args):
QWidget.__init__(self, *args)
self.image = image
def paintEvent(self, event):
painter = QPainter(self)
image = self.image.scaled(self.size(), Qt.KeepAspectRatio,
Qt.SmoothTransformation)
painter.drawImage(0, 0, image)
If you have pixmaps rather than images then replace the drawImage() call
with a drawPixmap() call.
David
More information about the PyQt
mailing list