def onColorPicker(self): dlg = QColorDialog() if self._color is not None: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_() == dlg.Accepted: self.setColor(dlg.currentColor().name())
def open_color_dialog(self, attr_name, mouse_event): d = QColorDialog(self) d.setCurrentColor(getattr(self, attr_name)) f = partial(self.set_color, attr_name) d.colorSelected.connect( f) # d.open(f) doesn't pass color for some reason d.open()
def showColorDialog(self): # leave fullscreen mode while the color selector is displayed # to prevent the color selector falling behind the fullscreen # window and the app being unclosable oldstate = self.windowState() self.setWindowState(oldstate & ~Qt.WindowFullScreen) tmpcolor = self.color def setColor(color): nonlocal tmpcolor self.setColor(color) tmpcolor = None color_dlg = QColorDialog() color_dlg.setCurrentColor(self.color) color_dlg.currentColorChanged.connect(self.setColor) color_dlg.colorSelected.connect(setColor) flags = self.windowFlags() color_dlg.setWindowFlags(flags | Qt.WindowStaysOnTopHint) color_dlg.exec_() if tmpcolor is not None: self.setColor(tmpcolor) self.setWindowState(oldstate)
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 ColorWellWidget(QPushButton): def __init__(self, size=QSize(50, 40), color=QColor(0, 0, 0)): QPushButton.__init__(self) self._color = color self._color_picker = QColorDialog() self.setFixedSize(size) self.setAutoFillBackground(True) self.set_color(color) self.clicked.connect(self._clicked_cb) self._callbacks = [] def set_color(self, color): palette = self.palette() role = self.backgroundRole() palette.setColor(role, color) self.setPalette(palette) self._color = color def _clicked_cb(self, event): self._color_picker.setCurrentColor(self._color) self.set_color(self._color_picker.getColor()) for callback in self._callbacks: callback(self._color) def connect(self, callback): self._callbacks.append(callback)
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 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 slot_call_color_dialog(self): dialog = QColorDialog(self) dialog.setCurrentColor(self.currentColor) if dialog.exec_() == QDialog.Accepted: self.currentColor = dialog.currentColor() self.updateImagePreview()
def showColorPicker(self): dialogue = QColorDialog() dialogue.setCurrentColor(self._colour) dialogue.setOption(QColorDialog.ShowAlphaChannel) if dialogue.exec_(): self.setColor(dialogue.currentColor())
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 on_treeView_doubleClicked(self, index): if index.column() not in [1, 2, 4]: return color = QColor(index.data(Qt.EditRole)) dialog = QColorDialog(self) dialog.setCurrentColor(color) if dialog.exec_() == QDialog.Accepted: self.pickedModel.setData(index, dialog.currentColor())
def edit(self, row, column): self._status = (row, self.listbox.item(row, column).background()) win = QColorDialog(self) win.setCurrentColor(self.listbox.item(row, column).background().color()) win.currentColorChanged.connect( self.intermediateColor) win.rejected.connect(self.setColor) win.open()
def __choose_color(self): dialog = QColorDialog(self.window()) dialog.setOption(QColorDialog.ShowAlphaChannel, True) dialog.setCurrentColor(QColor.fromRgba(self.__color.argb)) if dialog.exec_() == QColorDialog.Accepted: self.__color = Color(dialog.currentColor().rgba()) self.__refresh_label() self.color_changed.emit(self.__color)
def on_user_event(self): colord = QColorDialog()#self._color) colord.setOption(QColorDialog.DontUseNativeDialog) if self._kind == "rgbf": colord.setOption(QColorDialog.ShowAlphaChannel) colord.setCurrentColor(self._color) colord.setCustomColor(0, self._color) if colord.exec(): self.update_color(colord.currentColor())
def openPresplashPicker(self): object = self.specObjects['android_presplash_color'] dlg = QColorDialog(self) c = QColor(object.currentText()) dlg.setCurrentColor(c) color = dlg.getColor() if not color.isValid(): return object.setEditText(color.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()))
def PickColor(self): self.c_color = None dlg = QColorDialog(self) if self.c_color: dlg.setCurrentColor(QColor(self.c_color)) if dlg.exec_(): self.setColor(dlg.currentColor().name())
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 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 on_color_picker(self): ''' Show color-picker dialog to select color. Qt will use the native dialog by default. ''' dlg = QColorDialog(self) if self._color: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): self.set_color(dlg.currentColor().name())
def _doubleClicked(self, index): model = self.model() if model is None: return data = model.data(index) if isinstance(data, QColor): dialog = QColorDialog(self) dialog.setCurrentColor(data) ret = dialog.exec_() if ret: color = dialog.currentColor() model.setData(index, 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 mousePressEvent(self, event): scene_pos = self.mapToScene(event.pos()) pixmap = self.scene.itemAt(scene_pos) if not pixmap: return image = pixmap.pixmap().toImage() pos = int(scene_pos.x()), int(scene_pos.y()) if event.button() == Qt.LeftButton: dlg = QColorDialog() dlg.setCurrentColor(QColor(image.pixel(pos[0], pos[1]))) if dlg.exec_(): self.window.change_current_palette(pos, dlg.currentColor())
def onColorPicker(self): """ Show color-picker dialog to select color. Qt will use the native dialog by default. """ dlg = QColorDialog(self) if self._color: dlg.setCurrentColor(QColor(self._color)) if dlg.exec_(): self.setColor(dlg.currentColor()) self.colorChangedFromDialog.emit()
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 OnColorPicker(self, *_args): dialog = QColorDialog(self) # Set starting/default/previous value if self.color: dialog.setCurrentColor(QColor(self.color)) # On ok if dialog.exec_(): self.color = dialog.currentColor() rgbcolor = [ self.color.redF(), self.color.greenF(), self.color.blueF() ] self.is_changed.emit(rgbcolor)
def _doubleClicked(self, index): model = self.model() if model is None: return data = model.data(index) if isinstance(data, QColor): if QApplication.keyboardModifiers() & Qt.AltModifier: model.setData(index, QColor()) else: dialog = QColorDialog(self) dialog.setCurrentColor(data) dialog.setOption(QColorDialog.ShowAlphaChannel) ret = dialog.exec_() if ret: color = dialog.currentColor() model.setData(index, color)
class ColorInput(QPushButton, Input): def __init__(self, dtype): super().__init__(dtype=dtype) self._color_dialog = QColorDialog() self._palette = QPalette() self._init_widget() def set_value(self, value: list): color = QColor.fromRgbF(*value) self._set_display_color(color) self._color_dialog.setCurrentColor(color) def get_gl_value(self) -> np.ndarray: if self._dtype == DataType.Vec3_RGB: return np.array((self._color.getRgbF()[:3]), dtype=np.float32) else: raise TypeError( "Internal type {} not supported for ColorInput!".format( self._dtype)) def get_value(self) -> typing.Any: return self._color def _init_widget(self): self._color_dialog.currentColorChanged.connect( self._current_color_changed) self._color_dialog.setOption(QColorDialog.ShowAlphaChannel, True) self.clicked.connect(self._open_color_dialog) @pyqtSlot(QColor) def _current_color_changed(self, color: QColor): self._set_display_color(color) self.input_changed.emit() def _open_color_dialog(self): self._color_dialog.open() def _set_display_color(self, color: QColor): self._palette.setColor(QPalette.Button, color) self.setAutoFillBackground(True) self.setFlat(True) self.setPalette(self._palette) self.update() self._color = color
def on_pressed(self): """Button pressed event handler Shows color dialog and sets the chosen color. """ dlg = QColorDialog(self.parent()) dlg.setCurrentColor(self.color) dlg.setWindowTitle(self.title) dlg.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint) dlg.setWindowModality(Qt.ApplicationModal) dlg.setOptions(QColorDialog.DontUseNativeDialog) p = self.mapFromGlobal(QCursor.pos()) p.setX(p.x() + (self.rect().width() / 2)) p.setY(p.y() + (self.rect().height() / 2)) dlg.move(self.mapToGlobal(p)) if dlg.exec_(): self.color = dlg.currentColor() self.colorChanged.emit()
def choose_color(self): dlg = QColorDialog(self) dlg.setCurrentColor(QColor(self.color)) if dlg.exec_(): self.color = dlg.currentColor().name()
def onColorPicker(self): dialog = QColorDialog() dialog.setCurrentColor(self._color) if dialog.exec_(): self.set_color(dialog.currentColor())