Skip to content

Commit a2ebf42

Browse files
committed
Fixes for colorbutton.
1 parent 7b48339 commit a2ebf42

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

qtwidgets/colorbutton/colorbutton.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from PySide2.QtCore import Qt, Signal
99

1010

11+
1112
class ColorButton(QtWidgets.QPushButton):
1213
'''
1314
Custom Qt Widget to show a chosen color.
@@ -18,14 +19,15 @@ class ColorButton(QtWidgets.QPushButton):
1819

1920
colorChanged = Signal(object)
2021

21-
def __init__(self, *args, **kwargs):
22+
def __init__(self, *args, color=None, **kwargs):
2223
super(ColorButton, self).__init__(*args, **kwargs)
2324

2425
self._color = None
26+
self._default = color
2527
self.pressed.connect(self.onColorPicker)
2628

27-
def sizeHint(self):
28-
return QtCore.QSize(32,32)
29+
# Set the initial/default state.
30+
self.setColor(self._default)
2931

3032
def setColor(self, color):
3133
if color != self._color:
@@ -56,6 +58,6 @@ def onColorPicker(self):
5658

5759
def mousePressEvent(self, e):
5860
if e.button() == Qt.RightButton:
59-
self.setColor(None)
61+
self.setColor(self._default)
6062

61-
return super(ColorButton, self).mousePressEvent(e)
63+
return super(ColorButton, self).mousePressEvent(e)

qtwidgets/colorbutton/demo_pyqt5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Window(QtWidgets.QMainWindow):
77
def __init__(self):
88
super().__init__()
99

10-
palette = ColorButton()
10+
palette = ColorButton(color='red')
1111
palette.colorChanged.connect(self.show_selected_color)
1212
self.setCentralWidget(palette)
1313

qtwidgets/colorbutton/demo_pyside2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Window(QtWidgets.QMainWindow):
77
def __init__(self):
88
super().__init__()
99

10-
palette = ColorButton()
10+
palette = ColorButton(color='red')
1111
palette.colorChanged.connect(self.show_selected_color)
1212
self.setCentralWidget(palette)
1313

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
version = '0.16'
3+
version = '0.17'
44

55
with open("README.md", "r") as fh:
66
long_description = fh.read()

0 commit comments

Comments
 (0)