def lineEditTextEdited(self): try: from ceed.cegui.ceguitypes import Colour newQColor = Colour.fromString(self.colourEditbox.text()).toQColor() if newQColor.isValid(): self.setColour(newQColor, "editbox") except: return
def setColour(self, newQColor, source=""): """ Displays the colour on the button using a stylesheet, and on the editbox using the regular setter for the string. :param newQColor: QtGui.QColor :return: """ buttonStyleSheet = """ QPushButton {{ margin: 1px; border-color: {borderColour}; border-style: outset; border-radius: 3px; border-width: 1px; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 {normalFirstColour}, stop: 0.7 {normalFirstColour}, stop: 1 {normalSecondColour}); }} QPushButton:pressed {{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 {pushedFirstColour}, stop: 0.7 {pushedFirstColour}, stop: 1 {pushedSecondColour}); }} """ firstColourStr = newQColor.toRgb().name() borderColour = QtGui.QColor() if newQColor.lightness() >= 123: borderLightness = 0 else: borderLightness = 255 borderColour.setHsl(-1, 0, borderLightness) borderColourStr = borderColour.toRgb().name() secondColourStr = newQColor.darker(150).toRgb().name() thirdColourStr = newQColor.darker(200).toRgb().name() buttonStyleSheet = buttonStyleSheet.format( borderColour=borderColourStr, normalFirstColour=firstColourStr, normalSecondColour=secondColourStr, pushedFirstColour=secondColourStr, pushedSecondColour=thirdColourStr) self.colourButton.setStyleSheet(buttonStyleSheet) if source != "editbox": from ceed.cegui.ceguitypes import Colour colourAsAlphaRGBString = str(Colour.fromQColor(newQColor)) self.colourEditbox.setText(colourAsAlphaRGBString) self.colourEditbox.setFocus() self.colourEditbox.selectAll() self.selectedColor = newQColor super(ColourValuePropertyEditor, self).valueChanging()
def setColour(self, newQColor, source=""): """ Displays the colour on the button using a stylesheet, and on the editbox using the regular setter for the string. :param newQColor: QtGui.QColor :return: """ buttonStyleSheet = """ QPushButton {{ margin: 1px; border-color: {borderColour}; border-style: outset; border-radius: 3px; border-width: 1px; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 {normalFirstColour}, stop: 0.7 {normalFirstColour}, stop: 1 {normalSecondColour}); }} QPushButton:pressed {{ background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 {pushedFirstColour}, stop: 0.7 {pushedFirstColour}, stop: 1 {pushedSecondColour}); }} """ firstColourStr = newQColor.toRgb().name() borderColour = QtGui.QColor() if newQColor.lightness() >= 123: borderLightness = 0 else: borderLightness = 255 borderColour.setHsl(-1, 0, borderLightness) borderColourStr = borderColour.toRgb().name() secondColourStr = newQColor.darker(150).toRgb().name() thirdColourStr = newQColor.darker(200).toRgb().name() buttonStyleSheet = buttonStyleSheet.format(borderColour=borderColourStr, normalFirstColour=firstColourStr, normalSecondColour=secondColourStr, pushedFirstColour=secondColourStr, pushedSecondColour=thirdColourStr) self.colourButton.setStyleSheet(buttonStyleSheet) if source != "editbox": from ceed.cegui.ceguitypes import Colour colourAsAlphaRGBString = str(Colour.fromQColor(newQColor)) self.colourEditbox.setText(colourAsAlphaRGBString) self.colourEditbox.setFocus() self.colourEditbox.selectAll() self.selectedColor = newQColor super(ColourValuePropertyEditor, self).valueChanging()