[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] How do I scale background image used in brush-palette?
From:       "Marc Nations" <mnations.lists () gmail ! com>
Date:       2008-12-23 17:32:11
Message-ID: f4010570812230932l5648c42es904ea004d866e51b () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Howdy,

I am trying to place a background image in the main centralWidget of my app.
It will serve as the backdrop on which all of the other widgets will sit. A
simple change that will give it a much more professional appearance.

I have been able to achieve this by placing the image as a pixmap into a
brush and then inserting that into a palette:

brush = QtGui.QBrush(QtGui.QPixmap("Images/bluebg.jpg"))
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Background, brush)
self.ui.centralwidget.setPalette(palette)


This doesn't scale the picture to be the same size as the centralWidget and
displays the picture as its natural size. This works as long as the picture
is larger than the application. I then tried to scale the picture with the
scale function:

brush =
QtGui.QBrush(QtGui.QPixmap("Images/bluebg.jpg").scaled(self.ui.centralwidget.size()))

This turns the image into wallpaper, which I guess is working as intended
since the Texture function is designed to apply the texture in wallpaper
format. The problem is there doesn't appear to be an option to set the
Texture to just display the image.

Is there a way to scale the image so that it assumes the size of the target
widget, or should be approaching this in a different manner?

Thanks

[Attachment #5 (text/html)]

<div>Howdy,</div>
<div>&nbsp;</div>
<div>I am trying to place a background image in the main centralWidget of my app. It \
will serve as the backdrop on which all of the other widgets will sit. A simple \
change that will give it a much more professional appearance.</div>

<div>&nbsp;</div>
<div>I have been able to achieve this by placing the image as a pixmap into a brush \
and then inserting that into a palette:</div> <blockquote dir="ltr" \
style="MARGIN-RIGHT: 0px"> <div>brush = \
QtGui.QBrush(QtGui.QPixmap(&quot;Images/bluebg.jpg&quot;))</div> \
<div>palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Background, brush)</div> \
<div>self.ui.centralwidget.setPalette(palette)</div></blockquote> <div>&nbsp;</div>
<div>This&nbsp;doesn&#39;t scale the picture to be the same size as the centralWidget \
and displays the picture as its natural size. This works as long as the picture is \
larger than the application. I then tried to scale the picture with the scale \
function:</div>

<blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
<div>brush = QtGui.QBrush(QtGui.QPixmap(&quot;Images/bluebg.jpg&quot;).scaled(self.ui.centralwidget.size()))</div></blockquote>
 <div>This turns the image into wallpaper, which I guess is working as intended since \
the Texture function is designed to apply the texture in wallpaper format. The \
problem is there doesn&#39;t appear to be an option to&nbsp;set the Texture to just \
display the image.&nbsp;</div>

<div>&nbsp;</div>
<div>Is&nbsp;there a way to scale the image&nbsp;so that it assumes the size of the \
target widget, or&nbsp;should be approaching this in a different manner?</div> \
<div>&nbsp;</div> <div>Thanks&nbsp;</div>
<div>&nbsp;</div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic