[PySide] custom paint method and QLayout.spacing()

Frank Rueter | OHUfx frank at ohufx.com
Tue Jul 10 09:13:00 CEST 2012


|Hi all,


I am having difficulties with something I thought was going to be simple:
I've got a custom button widget that uses it's own paint() function. I then place multiple instances of this in a QGrisLayout.
The problem is that the layout's spacing doesn't effect the custom button when the paint() function is re-implemented.
I am filling self.rect() with the background color which might be the problem?
Here is an example that probably shows better what I'm after. The QPushButtons have the layout's spacing in between each instance while the custom buttons don't.
I'm sure it's blatantly obvious what I'm doing wrong here, but I can't spot it.

Any help would be great!

Cheers,
frank

import  sys
from  PySide.QtGui  import  *
from  PySide.QtCore  import  *
class  CustomButton(QPushButton):
     def  __init__(self,  tool,  icon=None,  parent=None):
         super(CustomButton,  self).__init__(parent)
         self.setSizePolicy(QSizePolicy.Expanding,   QSizePolicy.Fixed)
         self.setMinimumWidth(200)
         self.frameGeometry()

     def  paintEvent(self,  event):
         painter=  QPainter(self)
         bgColor=  QColor(60,  60,  60)
         painter.fillRect(self.rect(),  bgColor)

app=  QApplication(sys.argv)
mainWindow=  QWidget()
grid=  QGridLayout()
grid.setSpacing(10)
mainWindow.setLayout(grid)
for  iin  xrange(4):
     btn1=  CustomButton('A')
     btn2=  QPushButton('B')
     grid.addWidget(btn1,  0,  i)
     grid.addWidget(btn2,  1,  i)
|

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120710/66c3e84d/attachment.html>


More information about the PySide mailing list