Creating a rectangular icon
Antony Loebs
barefootedjournalist at gmail.com
Thu Feb 25 22:29:10 CET 2010
I have been trying to figure out how to display a rectangular image in the
panel to use as a button. The image itself is 30x120, but I can't get it to
display to my satisfaction. If I use IconWidget, the image is squashed into
a square. If I use PushButton, the image is likewise squashed by the
button's borders. I tried changing the stylesheet for the button, setting
margin and padding to 0, but with no success. Below is the sample code (the
PushButton code is commented out).
---
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript
class PanelButton(plasmascript.Applet):
def __init__(self,parent,args=None):
plasmascript.Applet.__init__(self,parent)
def init(self):
self.setAspectRatioMode(Plasma.KeepAspectRatio)
# No configuration interface supported
self.setHasConfigurationInterface(False)
self.theme = Plasma.Svg(self)
self.theme.setImagePath("widgets/background")
self.setBackgroundHints(Plasma.Applet.DefaultBackground)
self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet)
#self.button = Plasma.PushButton(self.applet)
#self.button.setImage(self.package().path() +
"contents/images/image.png")
#self.button.setStyleSheet = ("margin: 0px; padding: 0px;")
#self.connect(self.button, SIGNAL("clicked()"), self.notify)
self.button = Plasma.IconWidget(self.applet)
self.button.setIcon(self.package().path() +
"contents/images/image.png")
self.connect(self.button, SIGNAL("clicked()"), self.notify)
self.layout.addItem(self.button)
self.applet.setLayout(self.layout)
self.resize(120, 30)
def notify(self):
pass
def CreateApplet(parent):
return PanelButton(parent)
---
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/plasma-devel/attachments/20100225/8874d84b/attachment.htm
More information about the Plasma-devel
mailing list