def paintEvent(self, event): painter = QtGui.QStylePainter(self) option = QtGui.QStyleOptionTab() if not self.colors: for i in range(self.count()): self.colors.append('gray') for i, tab_color in enumerate(self.colors): self.initStyleOption(option, i) color = Qt4Gui.QColor(tab_color) color.setAlpha(96) linearGrad = QtGui.QLinearGradient(QtCore.QPointF(0, 0), QtCore.QPointF(0, 1)) linearGrad.setColorAt(0, color) linearGrad.setColorAt(1, QtCore.Qt.transparent) brush = QtGui.QBrush(linearGrad) color_selected = Qt4Gui.QColor(tab_color) color_selected.setAlpha(168) linearGrad = QtGui.QLinearGradient(QtCore.QPointF(0, 0), QtCore.QPointF(0, 20)) linearGrad.setColorAt(0, color_selected) linearGrad.setColorAt(1, QtCore.Qt.transparent) brush_selected = QtGui.QBrush(linearGrad) option.palette.setBrush(Qt4Gui.QPalette.Normal, Qt4Gui.QPalette.Button, brush) option.palette.setBrush(Qt4Gui.QPalette.Normal, Qt4Gui.QPalette.Background, brush_selected) painter.setCompositionMode(QtGui.QPainter.CompositionMode_Lighten) painter.drawControl(QtGui.QStyle.CE_TabBarTab, option)
def setPaletteFromDct(dct): palette = Qt4Gui.QPalette() for role in roles: for group in groups: color = Qt4Gui.QColor(dct['%s:%s' % (role, group)]) qGrp = getattr(Qt4Gui.QPalette, group) qRl = getattr(Qt4Gui.QPalette, role) palette.setColor(qGrp, qRl, color) QtGui.QApplication.setPalette(palette)
def fill_status(self): status_combo_box = self.statusComboBox.model() for value, color in zip(self.task_process['process'], self.task_process['color']): item = Qt4Gui.QStandardItem(u'{0}'.format(value)) sc = gf.hex_to_rgb(color, tuple=True) sc_item = Qt4Gui.QColor(sc[0], sc[1], sc[2], 128) item.setBackground(sc_item) item.setData(sc_item, 1) item.setData(value, 2) status_combo_box.appendRow(item)
def fill_priority(self): # priority combo box with colors priority_combo_box = self.priorityComboBox.model() step = len(self.priority) - 1 int_range = 255 / step * step r = range(0, int_range, 255 / step) g = range(0, int_range, 255 / step) b = 0 a = 64 r.reverse() pc = [] for i in range(step): color = r[i], g[i], b, a pc.append(color) for i, (label, value) in enumerate(self.priority): item = Qt4Gui.QStandardItem(u'{0}, {1}'.format(label, value)) color = Qt4Gui.QColor(pc[i - 1][0], pc[i - 1][1], pc[i - 1][2], pc[i - 1][3]) if i > 0: item.setBackground(color) item.setData(color, 1) priority_combo_box.appendRow(item)