def setButtonColor(self, button, color): qcolor = QColor() qcolor.setRgbF(color[0], color[1], color[2]) palette = QPalette() palette.setColor(QPalette.Button, qcolor) button.setPalette(palette)
def __init__(self, parent=None): super(TreeWidget, self).__init__(parent) self._auto_add_sub_items = True self._title_text_index = 0 self._text_edit = True self._edit_state = None self._current_name = None self._old_name = None self._current_item = None self._last_item = None self._drop_indicator_rect = QRect() self._drop_indicator_position = None self._name_filter = None self.setIndentation(25) self.setExpandsOnDoubleClick(False) self.setSortingEnabled(True) self.sortByColumn(0, Qt.AscendingOrder) if dcc.is_maya(): self.setAlternatingRowColors(dcc.get_version() < 2016) if not dcc.is_maya() and not not dcc.is_nuke(): palette = QPalette() palette.setColor(palette.Highlight, Qt.gray) self.setPalette(palette) self.itemActivated.connect(self._on_item_activated) self.itemChanged.connect(self._on_item_changed) self.itemSelectionChanged.connect(self._on_item_selection_changed) self.itemClicked.connect(self._on_item_clicked) self.itemExpanded.connect(self._on_item_expanded) self.itemCollapsed.connect(self._on_item_collapsed)
def create_rubber_band(self): """ Creates a new instance of the selection rubber band :return: QRubberBand """ rubber_band = QRubberBand(QRubberBand.Rectangle, self) palette = QPalette() color = self.rubber_band_color() palette.setBrush(QPalette.Highlight, QBrush(color)) rubber_band.setPalette(palette) return rubber_band
def __init__(self, baseColor=QColor("#f7f7f7"), highlightColor=QColor("#2196F3"), spread=2.5): """Constructor By default a nukeish color scheme (dark slate + orange highlight) is created This can be overriden by either supplying colors or by loading a different scheme from disc via the load settings """ self.palette = QPalette() self.baseColor = baseColor self.highlightColor = highlightColor self.spread = spread self.generateScheme() QApplication.setStyle("Plastique")
def OnColorPicked(self): """ Event to call color picker """ dialog = QColorDialog(self.color_swatch.qcolor, self) if dialog.exec_(): self.color_swatch.setPalette(QPalette(dialog.currentColor())) self.color_swatch.qcolor = dialog.currentColor() self.color_swatch._update() self.OnValueUpdated()
def ui(self): super(ExpandablePanel, self).ui() widget_palette = QPalette() widget_palette.setColor(QPalette.Background, QColor.fromRgb(60, 60, 60)) self.setAutoFillBackground(True) self.setPalette(widget_palette) frame = QFrame() frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Sunken) self.main_layout.addWidget(frame) main_layout = layouts.VerticalLayout(spacing=0, margins=(2, 2, 2, 2), parent=frame) main_layout.setAlignment(Qt.AlignTop) self._header_area = QWidget() self._header_area.setMinimumHeight(20) self._widget_area = QWidget() self._widget_area.setAutoFillBackground(True) self._widget_area.setPalette(widget_palette) self._header_text_label = dividers.Divider(self._header_text) self._widget_layout = layouts.VerticalLayout(spacing=5) self._widget_layout.setMargin(5) self._widget_area.setLayout(self._widget_layout) header_layout = layouts.HorizontalLayout(margins=(0, 0, 0, 0)) header_layout.addWidget(self._icon) header_layout.addWidget(self._header_text_label) self._header_area.setLayout(header_layout) main_layout.addWidget(self._header_area) main_layout.addWidget(self._widget_area) self._icon.clicked.connect(self.change_state)
def validate(value): try: if value: value = json.loads(value) else: value = None palette = QPalette() palette.setColor(widget.backgroundRole(), QColor('white')) widget.setPalette(palette) self.arguments[name] = value self.valid[name] = True except: palette = QPalette() palette.setColor(widget.backgroundRole(), QColor(255, 102, 102)) widget.setPalette(palette) self.valid[name] = False self.buttonBox.setEnabled(all(self.valid.values()))
class StrackColorScheme(object): """Class to ease custom colors of PyQt apps baseColor: This is the main background color. highlightColor: Typically contrasting the baseColor (e.g. used to highlight current focus) spread: Float value indicating the brightness range generated by generateColors (1.5-2.0 seems most reasonable) """ def __init__(self, baseColor=QColor("#f7f7f7"), highlightColor=QColor("#2196F3"), spread=2.5): """Constructor By default a nukeish color scheme (dark slate + orange highlight) is created This can be overriden by either supplying colors or by loading a different scheme from disc via the load settings """ self.palette = QPalette() self.baseColor = baseColor self.highlightColor = highlightColor self.spread = spread self.generateScheme() QApplication.setStyle("Plastique") def __lightness(self, color): """Returns simple averaged lightness of a QColor Newer Qt Versions implement this as part of QColor Reimplemented for backwards-compatibility """ hsv = color.toHsv() return hsv.valueF() def generateScheme(self, apply=True): """Generate color palette By default the generated palette is also applied to the whole application To override supply the apply=False argument """ BASE_COLOR = self.baseColor HIGHLIGHT_COLOR = self.highlightColor BRIGHTNESS_SPREAD = self.spread if self.__lightness(BASE_COLOR) > 0.5: SPREAD = 100 / BRIGHTNESS_SPREAD else: SPREAD = 100 * BRIGHTNESS_SPREAD if self.__lightness(HIGHLIGHT_COLOR) > 0.6: HIGHLIGHTEDTEXT_COLOR = BASE_COLOR.darker(SPREAD * 2) else: HIGHLIGHTEDTEXT_COLOR = BASE_COLOR.lighter(SPREAD * 2) self.palette.setBrush(QPalette.Window, QBrush(BASE_COLOR)) self.palette.setBrush(QPalette.WindowText, QBrush(BASE_COLOR.lighter(SPREAD * 2))) self.palette.setBrush(QPalette.Foreground, QBrush(BASE_COLOR.lighter(SPREAD))) self.palette.setBrush(QPalette.Base, QBrush(BASE_COLOR)) self.palette.setBrush(QPalette.AlternateBase, QBrush(BASE_COLOR.darker(SPREAD))) self.palette.setBrush(QPalette.ToolTipBase, QBrush(BASE_COLOR)) self.palette.setBrush(QPalette.ToolTipText, QBrush(BASE_COLOR.lighter(SPREAD))) self.palette.setBrush(QPalette.Text, QBrush(BASE_COLOR.lighter(SPREAD * 1.8))) self.palette.setBrush(QPalette.Button, QBrush(BASE_COLOR)) self.palette.setBrush(QPalette.ButtonText, QBrush(BASE_COLOR.lighter(SPREAD * 1.2))) self.palette.setBrush(QPalette.BrightText, QBrush(QColor("#ffffff"))) self.palette.setBrush(QPalette.Light, QBrush(BASE_COLOR.lighter(SPREAD))) self.palette.setBrush(QPalette.Midlight, QBrush(BASE_COLOR.lighter(SPREAD / 2))) self.palette.setBrush(QPalette.Dark, QBrush(BASE_COLOR.darker(SPREAD))) self.palette.setBrush(QPalette.Mid, QBrush(BASE_COLOR)) self.palette.setBrush(QPalette.Shadow, QBrush(BASE_COLOR.darker(SPREAD * 2))) self.palette.setBrush(QPalette.Highlight, QBrush(HIGHLIGHT_COLOR)) self.palette.setBrush(QPalette.HighlightedText, QBrush(HIGHLIGHTEDTEXT_COLOR)) if apply: QApplication.setPalette(self.palette) def applyStyle(self, target=QApplication): """Apply the color scheme in self.palette When called without arguments the whole application will be styled If a widget is supplied as argument only this widget will be styled """ target.setPalette(self.palette) def colorFromStringTuple(self, tuple): return QColor(int(tuple[0]), int(tuple[1]), int(tuple[2])) def loadSimpleScheme(self, file, apply=True): scheme = ConfigParser.ConfigParser() scheme.read(file) self.baseColor = self.colorFromStringTuple( scheme.get("AutoColors", "baseColor").split(",")) self.highlightColor = self.colorFromStringTuple( scheme.get("AutoColors", "highlightColor").split(",")) self.spread = float(scheme.get("AutoColors", "spread")) if apply: self.generateScheme() else: self.generateScheme(apply=False) def loadScheme(self, file): """TODO: Implement """ raise NotImplementedError