def open_colordialog(self, button): """ Open color dialog to get color for token Args: button: QPushButton """ color_dialog = QColorDialog() if color_dialog.exec_() == QColorDialog.Accepted: button.setStyleSheet("background-color: {}".format( color_dialog.selectedColor().name())) button.clearFocus() self.player_colors.append(color_dialog.selectedColor().name())
def __selectColourSlot(self, button): """ Private slot to select a color. @param button reference to the button been pressed @type QPushButton """ colorKey = button.property("colorKey") hasAlpha = button.property("hasAlpha") colDlg = QColorDialog(self) if hasAlpha: colDlg.setOptions(QColorDialog.ShowAlphaChannel) # Set current colour last to avoid conflicts with alpha channel colDlg.setCurrentColor(self.__coloursDict[colorKey][0]) colDlg.currentColorChanged.connect( lambda col: self.colourChanged.emit(colorKey, col)) colDlg.exec_() if colDlg.result() == colDlg.Accepted: colour = colDlg.selectedColor() size = button.iconSize() pm = QPixmap(size.width(), size.height()) pm.fill(colour) button.setIcon(QIcon(pm)) self.__coloursDict[colorKey][0] = colour # Update colour selection self.colourChanged.emit(colorKey, self.__coloursDict[colorKey][0])
class Demo(QWidget): def __init__(self): super().__init__() self.resize(300, 300) self.setWindowTitle('QFontDialog') self.label = QLabel('塘沽五中', self) self.label.move(100, 10) self.cd = QColorDialog(QColor(250, 0, 0), self) # 创建颜色对话框--但不显示 # 参数1 默认颜色 self.pl = QPalette() # 创建调色板 btn = QPushButton('按钮', self) btn.move(100, 250) btn.clicked.connect(self.AA) def color(self): self.pl.setColor(QPalette.Background, self.cd.selectedColor()) # 给调色板设置颜色 # QPalette.Background 表示设置背景色 # QPalette.WindowText 表示设置文本颜色 # selectedColor() 返回最终选择的颜色 self.setPalette(self.pl) # 给控件设置颜色 pass def AA(self): self.cd.open(self.color) # 点击确定按钮时会自动执行槽函数
def locs(): qcd = QColorDialog(parent=vis.get_main_window()) qcd.setWindowFlag(Qt.WindowStaysOnTopHint, True) qcd.setCurrentColor(QColor.fromRgbF(*vis.get_grid_coordinates_color())) qcd.exec() if qcd.result() == 1: vis.set_grid_coordinates_color((qcd.selectedColor().getRgbF()))
def add_mark(self, *args): """ Method adds color mark to card :param args: Event data """ # Limit for marks color if len(self.marks_colors) > 2: message = QMessageBox(QMessageBox.Information, "Внимание!", "Достигнут лимит по цветным меткам") message.setWindowIcon(QtGui.QIcon(":/icons/app.png")) message.exec_() return # Selecting color dialog = QColorDialog() dialog.exec_() color = dialog.selectedColor() # Adding mark self.marks_colors.append(color.name()) current_mark = QWidget() current_mark.setMinimumSize(22, 5) current_mark.setMaximumHeight(8) current_mark.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) current_mark.setStyleSheet("QWidget {background: " + color.name() + ";}") self.hlayout_marks.insertWidget(1, current_mark)
def bg(): qcd = QColorDialog(parent=vis.get_main_window()) qcd.setWindowFlag(Qt.WindowStaysOnTopHint, True) qcd.setCurrentColor(QColor.fromRgbF(*vis.get_background_color())) qcd.exec() if qcd.result() == 1: vis.set_background_color((qcd.selectedColor().getRgbF()[:3]))
def __selectColor(self): dlg = QColorDialog(self.penColor, self.toolBoxWidget) reply = dlg.exec_() if reply == QColorDialog.Accepted: self.penColor = dlg.selectedColor() self.__setPenBtnColor() self.imageLabel.setPaintPenColor(self.penColor) self.imageLabel1.setPaintPenColor(self.penColor)
def brd(): qcd = QColorDialog(parent=vis.get_main_window()) qcd.setOption(QColorDialog.ShowAlphaChannel) qcd.setWindowFlag(Qt.WindowStaysOnTopHint, True) qcd.setCurrentColor(QColor.fromRgbF(*vis.get_grid_border_color())) qcd.exec() if qcd.result() == 1: vis.set_grid_border_color((qcd.selectedColor().getRgbF()))
def ChangeCol(): qcd = QColorDialog(dialog) qcd.setWindowTitle('颜色选择') qcd.setCurrentColor(self.buttonColorVal) if qcd.exec() == QDialog.Accepted: self.buttonColorVal = qcd.selectedColor() self.buttonColor.setStyleSheet( 'QWidget {background-color:%s}' % self.buttonColorVal.name())
def cp(): cd = QColorDialog(parent=vis.get_main_window()) cd.setWindowFlag(Qt.WindowStaysOnTopHint, True) cd.setOptions(QColorDialog.ShowAlphaChannel) cd.setCurrentColor(QColor.fromRgbF(*vis.get_added_matter_color())) cd.exec() if cd.result() == 1: vis.set_added_matter_color((cd.selectedColor().getRgbF()))
class ColorButton(QPushButton): color_changed = pyqtSignal(QColor, name='color_changed') def __init__(self, init_color=(1., 0., 0., 1.)): super(ColorButton, self).__init__() # Set button parameters self.setFixedWidth(20) self.setFixedHeight(20) self.setStyleSheet("QPushButton{border: 0px;}") # Create icon img_path = get_image_path('circle.svg') self.pixmap = QIcon(img_path).pixmap(20) self.mask = self.pixmap.createMaskFromColor(QColor(0, 0, 0, 0)) r = int(init_color[0]*255) g = int(init_color[1]*255) b = int(init_color[2]*255) a = int(init_color[3]*255) self.pixmap.fill(QColor(r, g, b, a)) self.pixmap.setMask(self.mask) self.setIcon(QIcon(self.pixmap)) self.clicked.connect(self.change_color) def set_color(self, color): r = int(color[0]*255) g = int(color[1]*255) b = int(color[2]*255) a = int(color[3]*255) self.pixmap.fill(QColor(r, g, b, a)) self.pixmap.setMask(self.mask) self.setIcon(QIcon(self.pixmap)) def change_color(self): self.color_dialog = QColorDialog() res = self.color_dialog.exec_() if not res: return new_color = QColor(self.color_dialog.selectedColor()) self.pixmap.fill(new_color) self.pixmap.setMask(self.mask) self.setIcon(QIcon(self.pixmap)) self.color_changed.emit(new_color)
def getColorPolygonAndBrushStyle( initial_color: Union[QColor, Qt.GlobalColor, QGradient] = QColor(), initial_polygon: NodePolygon = NodePolygon.Circle, initial_brushstyle: Qt.BrushStyle = Qt.NoBrush, parent: Optional[QWidget] = None, title: str = '', options: Union[QColorDialog.ColorDialogOptions, QColorDialog.ColorDialogOption] = QColorDialog.ColorDialogOptions()) \ -> (QColor, NodePolygon): dlg = QColorDialog(parent) # Add buttons to select polygon polygons_group = QButtonGroup(parent) polygons_layout = QHBoxLayout(parent) for p in NodePolygon: if p == NodePolygon.Custom: continue button = QToolButton(parent) button.setCheckable(True) button.setText(p.name) button.setIcon(QIcon(nodePolygonToPixmap(p, button.iconSize()))) if p == initial_polygon: button.setChecked(True) polygons_group.addButton(button) polygons_group.setId(button, p.value) polygons_layout.addWidget(button) dlg.layout().insertLayout(dlg.layout().count()-1, polygons_layout) # Add buttons to select brush style brushstyle_group = QButtonGroup(parent) brushstyle_layout = QHBoxLayout(parent) for p in NODE_BRUSH_STYLES: button = QToolButton(parent) button.setCheckable(True) button.setIcon(QIcon(nodeBrushStyleToPixmap(p, button.iconSize()))) if p == initial_brushstyle: button.setChecked(True) brushstyle_group.addButton(button) brushstyle_group.setId(button, p) brushstyle_layout.addWidget(button) dlg.layout().insertLayout(dlg.layout().count()-1, brushstyle_layout) if title: dlg.setWindowTitle(title) dlg.setOptions(options) dlg.setCurrentColor(initial_color) dlg.exec_() return (dlg.selectedColor(), NodePolygon(polygons_group.checkedId()), brushstyle_group.checkedId(), )
def action_set_color_triggered(self): cd = QColorDialog(self.color) cd.exec_() this_color = cd.selectedColor() if this_color.isValid(): idx_GENOME = self.treeWidget().get_header_index(HEADER_GENOME) self.setBackground(idx_GENOME, this_color) self.color = this_color for i in range(0, self.childCount()): child = self.child(i) if child.plt is not None: child.plt.setPen(mkPen(color=self.color))
def onColorPicker(self): ''' Show color-picker dialog to select color. Qt will use the native dialog by default. ''' dlg = QColorDialog() if self._color: dlg.setCurrentColor(self._color) if dlg.exec_(): self.setColor(dlg.selectedColor())
def selectDrawColor(self): self.setBScale(False) colorDialog = QColorDialog(self) colorDialog.setWindowTitle('Select Draw Color: ') colorDialog.setCurrentColor(Qt.red) if colorDialog.exec_() == QColorDialog.Accepted: drawColor = colorDialog.selectedColor() self.canvas.setDrawColor(drawColor) red = drawColor.red() green = drawColor.green() blue = drawColor.blue() self.cfg.set('file', 'drawColorRed', str(red)) self.cfg.set('file', 'drawColorGreen', str(green)) self.cfg.set('file', 'drawColorBlue', str(blue)) self.cfg.write(open('SWQT.ini', 'w'))
def getColor( parent = None, title = "", color = None, alpha = False, ): """Ask the user a color.""" global _savedColor if color is None: color = _savedColor dlg = QColorDialog(color, parent) options = QColorDialog.ColorDialogOptions() if alpha: options |= QColorDialog.ShowAlphaChannel if not QSettings().value("native_dialogs/colordialog", True, bool): options |= QColorDialog.DontUseNativeDialog dlg.setOptions(options) dlg.setWindowTitle(title or app.caption(_("Select Color"))) if dlg.exec_(): _savedColor = dlg.selectedColor() return _savedColor
def getColor( parent=None, title="", color=None, alpha=False, ): """Ask the user a color.""" global _savedColor if color is None: color = _savedColor dlg = QColorDialog(color, parent) options = QColorDialog.ColorDialogOptions() if alpha: options |= QColorDialog.ShowAlphaChannel if not QSettings().value("native_dialogs/colordialog", True, bool): options |= QColorDialog.DontUseNativeDialog dlg.setOptions(options) dlg.setWindowTitle(title or app.caption(_("Select Color"))) if dlg.exec_(): _savedColor = dlg.selectedColor() return _savedColor
class Demo(QWidget): def __init__(self): super().__init__() self.resize(300, 300) self.setWindowTitle('QFontDialog') self.label = QLabel('塘沽五中', self) self.label.move(100, 10) self.cd = QColorDialog(QColor(250, 0, 0), self) # 创建颜色对话框--但不显示 # 参数1 默认颜色 self.pl = QPalette() # 创建调色板 btn = QPushButton('按钮', self) btn.move(100, 250) btn.clicked.connect(self.AA) # self.cd.setOption(QColorDialog.NoButtons) #选项控制--单个选项 # QColorDialog.NoButtons 不显示“ 确定”和“ 取消”按钮。(对“实时对话框”有用) # 参数2 on 表示有效 False表示取消 self.cd.setOptions(QColorDialog.NoButtons | QColorDialog.ShowAlphaChannel) # 选项控制--多个选项 # QColorDialog.ShowAlphaChannel 对话框中增加alpha设置项 self.cd.currentColorChanged.connect(self.BB) # 当前颜色变化时发出信号 def BB(self): s = self.cd.currentColor() # 返回当前颜色 # setCurrentColor(QColor()) 设置当前颜色 self.pl.setColor(QPalette.Background, s) self.setPalette(self.pl) def AA(self): r = self.cd.exec() if r: self.pl.setColor(QPalette.Background, self.cd.selectedColor()) # 给调色板设置颜色 self.setPalette(self.pl) # 给控件设置颜色
def _on_pick_tree(self, event): """a matplotlib callback function for when a tree is clicked on""" if event.artist != self._treepoints: # print "you clicked on something other than a node" return True ind = event.ind[0] self.tree_selected = self._tree_list[ind] print("tree clicked on", self.tree_selected) # launch a color selector dialog and color # all subtrees by the selected color color_dialog = QColorDialog(parent=self) color_dialog.exec_() if color_dialog.result(): color = color_dialog.selectedColor() rgba = color.getRgbF() # red green blue alpha print("color", rgba) rgb = rgba[:3] for tree in self.tree_selected.get_all_trees(): tree.data["colour"] = rgb self.redraw_disconnectivity_graph()
class Demo(QWidget): def __init__(self): super().__init__() self.resize(300, 300) self.setWindowTitle('QFontDialog') self.label = QLabel('塘沽五中', self) self.label.move(100, 10) self.cd = QColorDialog(QColor(250, 0, 0), self) # 创建颜色对话框--但不显示 # 参数1 默认颜色 self.pl = QPalette() # 创建调色板 btn = QPushButton('按钮', self) btn.move(100, 250) btn.clicked.connect(self.AA) def AA(self): r = self.cd.exec() # 用户点击确定按钮返回值1;用户点击取消按钮返回值0 if r: self.pl.setColor(QPalette.Background, self.cd.selectedColor()) # 给调色板设置颜色 self.setPalette(self.pl) # 给控件设置颜色
def getDlgClr(self,default): dlg = QColorDialog(QColor(default),self) dlg.setOption(QColorDialog.ShowAlphaChannel, on=True) if dlg.exec() == 1: return dlg.selectedColor().name(QColor.HexArgb) else: return default
def mousePressEvent(self, e): color_dialog = QColorDialog() color_dialog.exec_() self.current_color = color_dialog.selectedColor() self.reset_style_sheet()
def onChooseColor(self): colorDiag = QColorDialog() colorDiag.exec_() color = colorDiag.selectedColor() self.color = color.getRgb() self.styleColorBttn(self.color)
def mousePressEvent(self, e): color_dialog = QColorDialog() color_dialog.exec_() self.current_color = color_dialog.selectedColor() self.reset_style_sheet()
def chooseColor(self): colorDiag = QColorDialog() colorDiag.exec_() color = colorDiag.selectedColor() return color.getRgb()