qt - custom paint() not working with QLayout.setSpacing() -


After

I'm struggling to understand something simple:

I have a custom widget subclassification from QPushButton , From which the multiple instances of which I am laying in a QGridLayout () when I add a paint () function and fill the button's reset () to draw a background color, the layout's vacancies do not consider any further effect. . There is a screen shot to show, which means: Enter image details here

It shows the default QPushButtons that follow the layout of the layout and my custom "button" do not do that, I'm sure I need to implement something in my custombutton, but I do not know what this is. I tried to make no use to the content margin

What am I missing? Maybe I do not have to fill the self (right), but something else? Here is the example code that the screen shot is produced: PySide.QtCore Import from * class * CustomButton (QPushButton) to PySide.QtGui import * Import sys: def __init __ (tools, icons = None, Parents = None): Super (CustomButton, Self) .__ init __ (parent) self.setSizePolicy (QSizePolicy.Fixed) self.setMinimumWidth (200) self.frameGeometry () Def paintEvent ( Self, incident): painter = QPainter (self) bgcolor = Qcolor (60, 60, 60) painter.fillRect (self.rect (), bgcolor) application = QApplication (sys.argv) MainWindow = QWidget () grid = QGridLayout ( ) Grid.setspacing (10) xrange in mainwindow for i SetLayout (4): btn1 = CustomButton ('A') btn2 = QPushButton ('B') grid.addWidget (btn1, 0, i) grid.addWidget (btn2, 1, i) MainWindow.show () sys .exit (app.exec_ ())

Such a solution manually It seems to be a bit (right) to adjust, though I do not understand why it is necessary because I thought that what the e layout layout is for the following:

 < Code> def paintEvent (self, incident): rect = self.rect () rect.adjust (5,5, -5, -5) illustrator = QPainter (self) BgColor = QC Olor (60, 60, 60) painter.fillRect (rect, bgcolor)   

This should give me the space I need. If someone can put light on whether it is a bug or a feature, I am very grateful.

Comments