Merge pull request #1995 from Achilles1515/colorbutton-padding

Change hardcoded padding into initialization parameter
This commit is contained in:
Ogi Moore 2021-09-23 17:19:08 -07:00 committed by GitHub
commit e9d3b6ddd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -19,8 +19,9 @@ class ColorButton(QtGui.QPushButton):
sigColorChanging = QtCore.Signal(object) ## emitted whenever a new color is picked in the color dialog
sigColorChanged = QtCore.Signal(object) ## emitted when the selected color is accepted (user clicks OK)
def __init__(self, parent=None, color=(128,128,128)):
def __init__(self, parent=None, color=(128,128,128), padding=6):
QtGui.QPushButton.__init__(self, parent)
self.padding = (padding, padding, -padding, -padding) if isinstance(padding, (int, float)) else padding
self.setColor(color)
self.colorDialog = QtGui.QColorDialog()
self.colorDialog.setOption(QtGui.QColorDialog.ColorDialogOption.ShowAlphaChannel, True)
@ -37,7 +38,7 @@ class ColorButton(QtGui.QPushButton):
def paintEvent(self, ev):
super().paintEvent(ev)
p = QtGui.QPainter(self)
rect = self.rect().adjusted(6, 6, -6, -6)
rect = self.rect().adjusted(*self.padding)
## draw white base, then texture for indicating transparency, then actual color
p.setBrush(functions.mkBrush('w'))
p.drawRect(rect)