add custom colorbutton widget

This commit is contained in:
Phill Ridout 2014-10-23 20:50:01 +01:00
parent 5662f4b2af
commit a4f788599f
2 changed files with 34 additions and 0 deletions

View File

@ -318,6 +318,7 @@ def create_separated_list(string_list):
return translate('OpenLP.core.lib', '%s, %s', 'Locale list separator: start') % (string_list[0], merged)
from .colorbutton import ColorButton
from .filedialog import FileDialog
from .screen import ScreenList
from .listwidgetwithdnd import ListWidgetWithDnD

View File

@ -0,0 +1,33 @@
from PyQt4 import QtCore, QtGui
class ColorButton(QtGui.QPushButton):
"""
Subclasses QPushbutton to create a "Color Chooser" button
"""
colorChanged = QtCore.pyqtSignal(str)
def __init__(self, parent):
super(ColorButton, self).__init__()
self._color = '#ffffff'
self.parent = parent
self.clicked.connect(self.on_clicked)
def change_color(self, color):
self._color = color
self.setStyleSheet('background-color: %s' % color)
@property
def color(self):
return self._color
@color.setter
def color(self, color):
self.change_color(color)
def on_clicked(self):
new_color = QtGui.QColorDialog.getColor(QtGui.QColor(self._color), self.parent)
if new_color.isValid() and self._color != new_color.name():
self.change_color(new_color.name())
print("changed")
self.colorChanged.emit(new_color.name())