def __init__(self, searchPixmap=None, clearPixmap=None, parent=None): QtWidgets.QLineEdit.__init__(self, parent) if searchPixmap is None: searchPixmap = iconlib.iconColorized("magnifier", utils.dpiScale(16), (128,128,128)) # these should be in layouts if clearPixmap is None: clearPixmap = iconlib.iconColorized("close", utils.dpiScale(16), (128,128,128)) self.clearButton = QtWidgets.QToolButton(self) self.clearButton.setIcon(QtGui.QIcon(clearPixmap)) self.clearButton.setCursor(QtCore.Qt.ArrowCursor) self.clearButton.setStyleSheet("QToolButton { border: none; padding: 1px; }") self.clearButton.hide() self.clearButton.clicked.connect(self.clear) self.textChanged.connect(self.updateCloseButton) self.searchButton = QtWidgets.QToolButton(self) self.searchButton.setStyleSheet("QToolButton { border: none; padding: 0px; }") self.searchButton.setIcon(QtGui.QIcon(searchPixmap)) frameWidth = self.style().pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth) self.setStyleSheet("QLineEdit { padding-left: %dpx; padding-right: %dpx; } "%( self.searchButton.sizeHint().width() + frameWidth + 1, self.clearButton.sizeHint().width() + frameWidth + 1)) msz = self.minimumSizeHint() self.setMinimumSize(max(msz.width(), self.searchButton.sizeHint().width() + self.clearButton.sizeHint().width() + frameWidth * 2 + 2), max(msz.height(), self.clearButton.sizeHint().height() + frameWidth * 2 + 2))
def Spacer(width, height, hMin=QtWidgets.QSizePolicy.Minimum, vMin=QtWidgets.QSizePolicy.Minimum): """creates an expanding spacer (empty area) with easy options. DPI auto handled Size Policies are https://srinikom.github.io/pyside-docs/PySide/QtGui/QSizePolicy.html#PySide.QtGui.PySide.QtGui.QSizePolicy.Policy QtWidgets.QSizePolicy.Fixed - never grows or shrinks QtWidgets.QSizePolicy.Minimum - no advantage being larger QtWidgets.QSizePolicy.Maximum - no advantage being smaller QtWidgets.QSizePolicy.Preferred - The sizeHint() is best, but the widget can be shrunk/expanded QtWidgets.QSizePolicy.Expanding - but the widget can be shrunk or make use of extra space QtWidgets.QSizePolicy.MinimumExpanding - The sizeHint() is minimal, and sufficient QtWidgets.QSizePolicy.Ignored - The sizeHint() is ignored. Will get as much space as possible :param width: width of the spacer in pixels, DPI is auto handled :type width: int :param height: height of the spacer in pixels, DPI is auto handled :type height: int :param hMin: height of the spacer in pixels, DPI is auto handled :type hMin: PySide.QtGui.QSizePolicy.Policy :param vMin: vertical minimum :type vMin: PySide.QtGui.QSizePolicy.Policy :return spacerItem: item returned, ie the spacerItem :rtype spacerItem: object """ return QtWidgets.QSpacerItem(utils.dpiScale(width), utils.dpiScale(height), hMin, vMin)
def __init__(self, parent=None, size=24): """ Floating Button that can be placed anywhere on the screen Essentially a floating frameless transparent window. It doesn't float outside the parent, so make sure the button is within the parent bounds to be visible. .. code-block:: python # use .button to access the actual push button floatBtn = FloatingButton(parent=self) floatBtn.button.clicked.connect(self.floatButtonClicked) # Use .move to move it around the window. Note: It's not visible outside the parent's bounds floatBtn.move(20,20) # Use setAlignment() to align the edge of the FloatingButton when moving. floatBtn.setAlignment(QtCore.Qt.AlignTop) # Top of button will at the new move position floatBtn.setAlignment(QtCore.Qt.AlignLeft) # Bottom of button will at the new move position floatBtn.move(20,20) # Use move to update the position :param parent: """ super(FloatingButton, self).__init__(parent=parent, showOnInitialize=False) self.button = QtWidgets.QPushButton(parent=self) self.mainLayout = utils.hBoxLayout(self) self.resize(utils.dpiScale(size), utils.dpiScale(size)) self.alignment = QtCore.Qt.AlignBottom self.initUi() self.setStyleSheet("background-color: transparent;")
def __init__(self, text="", key=None, color=(255, 255, 255), parent=None, toolTip="", labelRatio=1, btnRatio=1, setFixedWidth=50, spacing=5): """Adds a maya color picker to a pyside label and colored button. Uses cmds.colorEditor which locks Maya :param text: label name :type text: str :param key: The stylesheet pref key eg. "FRAMELESS_TITLELABEL_COLOR" :type key: basestring :param color: the start color of the color button in rbg 255 (255, 255, 255) Color is srgb not linear :type color: tuple :param parent: the parent widegt :type parent: QtWidget :param toolTip: the tooltip on hover :type toolTip: str :param labelRatio: the width column ratio of the label/button corresponds to the ratios of labelRatio/btnRatio :type labelRatio: int :param btnRatio: the width column ratio of the label/button corresponds to the ratios of labelRatio/btnRatio :type btnRatio: int :param setFixedWidth: set the width of the color button in pixels, dpi handled :type setFixedWidth: int :param spacing: the spacing size between the label and the button in pixels, dpi handled :type spacing: int """ super(ColorCmdsWidget, self).__init__(parent=parent, key=key) self.disableState = False self._color = None self.colorPicker = extendedbutton.ExtendedButtonSimpleMenu(parent=self) self._color = color if text: self.label = layouts.Label(text, parent, toolTip=toolTip) # supports menu else: self.label = None layout = layouts.hBoxLayout(self) self.setColorSrgbInt(self._color) if setFixedWidth: self.colorPicker.setFixedWidth(utils.dpiScale(setFixedWidth)) self.colorPicker.setToolTip(toolTip) if text: layout.addWidget(self.label, labelRatio) self.label.setToolTip(toolTip) layout.addSpacing(utils.dpiScale(spacing)) layout.addWidget(self.colorPicker, btnRatio) self.setLayout(layout) self.connections()
def __init__(self, radioList=None, toolTipList=None, default=0, parent=None, vertical=False): """Horizontal group of radio buttons :param radioList: a list of radio button names (strings) :type radioList: list :param default: the default button to be checked as on, starts at 0 matching the list :type default: int :param parent: the parent widget :type parent: obj """ super(RadioButtonGroup, self).__init__(parent=parent) # todo: STYLESHEET needs to be in the stylesheet and not hardcoded # rgb(27, 27, 27) is the main color of the unchecked button # rgb(45, 45, 45) is the background color of the window, unchecked has no icon indicatorWH = utils.dpiScale(14) uncheckedWH = utils.dpiScale(10) borderRadius = utils.dpiScale(7) borderPx = utils.dpiScale(2) styleSheetF = "QRadioButton::indicator {0}" \ "width: {2}px; " \ "height: {2}px;{1}" \ "QRadioButton::indicator:unchecked " \ "{0}background: rgb(27, 27, 27); " \ "width: {3}px; " \ "height: {3}px;" \ "border-radius: {4}px; " \ "border: {5}px solid rgb(45, 45, 45){1}".format("{", "}", indicatorWH, uncheckedWH, borderRadius, borderPx) if radioList is None: radioList = [] self.radioButtons = [] self.group = QtWidgets.QButtonGroup(parent=self) if not vertical: radioLayout = QtWidgets.QHBoxLayout() else: radioLayout = QtWidgets.QVBoxLayout() for i, radioName in enumerate(radioList): newRadio = QtWidgets.QRadioButton(radioName, self) newRadio.setStyleSheet(styleSheetF) if toolTipList: newRadio.setToolTip(toolTipList[i]) self.group.addButton(newRadio) radioLayout.addWidget(newRadio) self.radioButtons.append(newRadio) if default is not None and default < len(self.radioButtons): self.radioButtons[default].setChecked(True) self.group.buttonClicked.connect(self.toggled.emit) self.setLayout(radioLayout)
def setFixedSize(self, size): """ Sets fixed size :param size: Dpiscaling is automatically applied here :return: """ return super(ExtendedButton, self).setFixedSize(utils.dpiScale(size))
def setSpacingY(self, spacing): """Y Spacing for each item :param spacing: :return: """ self.spacingY = utils.dpiScale(spacing)
def format(self, settings): """Formats the stylesheet str with the settings :param settings: A dict containing the str to replace and the value to replace with eg. {"BACK_COLOR_R": 251} :type settings: dict :return: True if successfully formatted :rtype: bool """ if not self.data: return False data = str(self.data) for key, value in settings.items(): replaceVal = value if valueType(value) == DPI_SCALE: replaceVal = utils.dpiScale(int(value[1:])) if valueType(value) == ICON: path = iconlib.iconPathForName(value[5:]) if path == "": logger.warning( "Warning: \"{}\" icon not found for key: \"{}\" in stylesheet.pref" .format(value[5:], key)) replaceVal = os.path.normcase(path).replace("\\", "/") data = data.replace(key, str(replaceVal)) self.data = data return True
def __init__(self, label="", items=(), parent=None, labelRatio=None, boxRatio=None, toolTip="", setIndex=0): """Creates a searchable combo box (drop down menu) with a label :param label: the label of the combobox :type label: str :param items: the item list of the combobox :type items: tuple :param parent: the qt parent :type parent: class """ super(ComboBoxSearchable, self).__init__(parent=parent) layout = HBoxLayout(parent=None, margins=(0, 0, 0, 0), spacing=utils.dpiScale(uiconstants.SPACING)) # margins kwarg should be added self.box = combobox.ExtendedComboBox(items, parent) self.box.setToolTip(toolTip) if setIndex: self.box.setCurrentIndex(setIndex) if label: self.label = Label(label, parent, toolTip) if labelRatio: layout.addWidget(self.label, labelRatio) else: layout.addWidget(self.label) if boxRatio: layout.addWidget(self.box, boxRatio) else: layout.addWidget(self.box) layout.addWidget(self.box) self.setLayout(layout) self.box.currentIndexChanged.connect(self.onItemChanged)
def __init__(self, label="Color:", initialRgbColor=None, initialRgbColorF=None, contentsMargins=(0, 0, 0, 0), parent=None, labelWeight=1, colorWeight=1, colorWidth=None): """Initialize variables :param label: The name of the label, usually "Color:" :type label: str :param initialRgbColor: The initial rgb color in 0-255 ranges, overridden if there's a initialRgbColorF value :type initialRgbColor: tuple :param initialRgbColorF: The initial rgb color in 0-1.0 ranges, if None defaults to initialRgbColor values :type initialRgbColorF: tuple :param parent: the widget parent :type parent: class """ super(labelColorBtn, self).__init__(parent=parent) self.layout = HBoxLayout(parent=None, margins=utils.marginsDpiScale(*contentsMargins), spacing=utils.dpiScale(uiconstants.SPACING)) self.layout.addWidget(QtWidgets.QLabel(label, parent=self), labelWeight) self.colorPickerBtn = QtWidgets.QPushButton("", parent=self) # use initialRgbColor (255 range) or initialRgbColorF (float range 0-1) # if no color given then default to red self.storedRgbColor = initialRgbColor or tuple([i * 255 for i in initialRgbColorF]) or tuple([255, 0, 0]) self.colorPickerBtn.setStyleSheet("background-color: rgb{}".format(str(self.storedRgbColor))) if colorWidth: self.colorPickerBtn.setFixedWidth(colorWidth) self.layout.addWidget(self.colorPickerBtn, colorWeight) self.setLayout(self.layout) self.connections()
def setFixedHeight(self, height): """ DpiScaling version of set fixed height :param height: :return: """ return super(ExtendedButton, self).setFixedHeight(utils.dpiScale(height))
def colorConnectedDoubleClick(self, widget): # todo: add to button under double click, this version differs in the mini=False cmds flag pos = QtGui.QCursor.pos() rgb = colour.rgbIntToFloat(self._color) posX = pos.x() + utils.dpiScale(-220) posY = pos.y() + utils.dpiScale(-130) linearColorResult = cmds.colorEditor(mini=False, position=[posX, posY], rgbValue=rgb[:3]) linearColorResult = linearColorResult.strip().replace(" ", " ").split(" ") linearColorResult = map(float, linearColorResult) rgbColorResult = colour.convertColorLinearToSrgb( linearColorResult) # color is 0-1 float style self.setColorSrgbInt( colour.rgbFloatToInt(rgbColorResult)) # expects 255 color style
def setFixedWidth(self, width): """ DpiScaling version of set fixed width :param width: :return: """ return super(ExtendedButton, self).setFixedWidth(utils.dpiScale(width))
def GridLayout(parent=None, margins=(0, 0, 0, 0), spacing=uiconstants.SREG, columnMinWidth=None): """One liner for QtWidgets.QGridLayout() to make it easier to create an easy Grid layout DPI (4k) is handled here Defaults use regular spacing and no margins :param margins: override the margins with this value :type margins: tuple :param spacing: override the spacing with this pixel value :type spacing: int :param columnMinWidth: option for one column number then it's min width, use obj.setColumnMinimumWidth for more :type columnMinWidth: tuple """ zooGridLayout = QtWidgets.QGridLayout() zooGridLayout.setContentsMargins(*utils.marginsDpiScale(*margins)) zooGridLayout.setSpacing(utils.dpiScale(spacing)) if columnMinWidth: # column number then the width in pixels zooGridLayout.setColumnMinimumWidth(columnMinWidth[0], utils.dpiScale(columnMinWidth[1])) return zooGridLayout
def colorConnected(self, widget): # todo: the window position should compensate if on the edge of the screen. self.colorClicked.emit() if self.disableState: return pos = QtGui.QCursor.pos() srgb = colour.rgbIntToFloat(self._color) linearRgb = colour.convertColorSrgbToLinear(srgb) posX = pos.x() + utils.dpiScale(-220) posY = pos.y() + utils.dpiScale(-130) linearColorResult = cmds.colorEditor(mini=True, position=[posX, posY], rgbValue=linearRgb[:3]) linearColorResult = linearColorResult.strip().replace(" ", " ").split(" ") linearColorResult = [float(i) for i in linearColorResult] rgbColorResult = colour.convertColorLinearToSrgb( linearColorResult) # color is 0-1 float style self.setColorSrgbInt( colour.rgbFloatToInt(rgbColorResult)) # expects 255 color style
def _setupFilter(self): self.reloadBtn = QtWidgets.QToolButton(parent=self) # TODO: this button color needs stylesheeting once Stylesheeting is moved to zoocore self.reloadBtn.setIcon(iconlib.iconColorized("reload", color=(255, 255, 255))) self.searchLayout = QtWidgets.QHBoxLayout(self) self.searchLayout.setContentsMargins(0, 0, 0, 0) self.searchLayout.addWidget(self.reloadBtn) self.searchWidget = viewfilterwidget.ViewSearchWidget(showColumnVisBox=False, showHeaderBox=False, parent=self) self.searchWidget.setFixedHeight(utils.dpiScale(23)) self.searchLayout.addWidget(self.searchWidget) self.mainLayout.addLayout(self.searchLayout)
def BtnTransparentBG(**kwargs): """Create a button with a transparent bg. Saves code from doing this over and over Default Icon colour (None) is light grey and turns white (lighter in color) with mouse over. *Note WIP: Will fill out more options with time :param **kwargs: See the doc string from the function BtnStyle :type **kwargs: dict :return qtBtn: returns a qt button widget :rtype qtBtn: object """ parent = kwargs.get("parent") text = kwargs.get("text") icon = kwargs.get("icon", (255, 255, 255)) toolTip = kwargs.get("toolTip", "") iconColor = kwargs.get("iconColor") minWidth = kwargs.get("minWidth") maxWidth = kwargs.get("maxWidth") minHeight = kwargs.get("maxHeight") maxHeight = kwargs.get("maxHeight") btn = ExtendedButton(parent=parent, text=text) if icon: btn.setIconByName(icon, colors=iconColor) """ todo: icon colorized anti aliasing is not working correctly? Icons appear thicker # will want this code later self.setIcon(iconlib.iconColorized(icon, size=iconSize, color=iconColor, overlayName=overlayIconName, overlayColor=overlayIconColor)) """ btn.setToolTip(toolTip) if minWidth is not None: btn.setMinimumWidth(utils.dpiScale(minWidth)) if maxWidth is not None: btn.setMaximumWidth(utils.dpiScale(maxWidth)) if minHeight is not None: btn.setMinimumHeight(utils.dpiScale(minHeight)) if maxHeight is not None: btn.setMaximumHeight(utils.dpiScale(maxHeight)) return btn
def VBoxLayout(parent=None, margins=(0, 0, 0, 0), spacing=uiconstants.SREG): """One liner for QtWidgets.QVBoxLayout() to make it easier to create an easy Vertical Box layout DPI (4k) is handled here Defaults use regular spacing and no margins :param margins: override the margins with this value :type margins: tuple :param spacing: override the spacing with this pixel value :type spacing: int """ zooQVBoxLayout = QtWidgets.QVBoxLayout(parent) zooQVBoxLayout.setContentsMargins(*utils.marginsDpiScale(*margins)) zooQVBoxLayout.setSpacing(utils.dpiScale(spacing)) return zooQVBoxLayout
def __init__(self, text="", color=(1, 1, 1), parent=None, colorWidth=120, colorHeight=22, toolTip="blah", labelRatio=50, btnRatio=50, spacing=5): """Custom embedded cmds widget written Chris Zurbrigg see his tutorials http://zurbrigg.com/tutorials :param color: :type color: :param parent: :type parent: """ super(MayaColorSlider, self).__init__(parent) self.setObjectName("CustomColorButton") self.btnRatio = btnRatio self.colorWidth = colorWidth # create widgets if text: self.label = layouts.Label(text, parent, toolTip=toolTip) # supports menu else: self.label = None self.main_layout = layouts.hBoxLayout(self) if text: self.main_layout.addWidget(self.label, labelRatio) self.label.setToolTip(toolTip) self.main_layout.addSpacing(utils.dpiScale(spacing)) self._createControl( ) # creates self._color_widget which is the color picker and adds it to the layout self._color_widget.setToolTip(toolTip) # color widget setup self._colorLinear = color self._updateColor() if colorHeight: self.setHeight(colorHeight) self.setLayout(self.main_layout)
def __init__(self, label, value, min, max, axis, parent=None, step=0.1, setDecimals=2): """Creates a double spinbox for axis and lays them out in a horizontal layout We give access to each spinbox with a property eg. self.x which returns the float value :param label: the label for the vector eg. translate, if the label is None or "" then it will be excluded :type label: str :param value: n floats corresponding with axis param :type value: tuple(float) :param min: the min value for all three elements of the vector :type min: float :param max: the max value for all three elements of the vector :type max: float :param axis: every axis which will have a doubleSpinBox eg. [X,Y,Z] or [X,Y,Z,W] :type axis: list :param parent: the widget parent :type parent: QtWidget :param step: the step amount while clicking on the spin box or keyboard up/down :type step: float """ super(VectorSpinBox, self).__init__(parent=parent) self.mainLayout = HBoxLayout(parent, (2, 2, 2, 2), uiconstants.SREG) if label: self.label = QtWidgets.QLabel(label, parent=self) self.mainLayout.addWidget(self.label) self._widgets = OrderedDict() # todo: STYLESHEET needs to be in stylesheet and prefs # rgb(27, 27, 27) is the QLineEdit/QDoubleSpinBox color # images will need to be added and tweaked for hover states and press borderSize = utils.dpiScale(3) styleSheet = "QDoubleSpinBox {0} border: {2}px solid rgb(27, 27, 27); " \ "border-radius: 0px; {1}".format("{", "}", borderSize) for i, v in enumerate(axis): box = QtWidgets.QDoubleSpinBox(self) box.setSingleStep(step) box.setObjectName("".join([label, v])) box.setRange(min, max) box.setValue(value[i]) box.setDecimals(setDecimals) box.valueChanged.connect(self.onValueChanged) box.setStyleSheet(styleSheet) self._widgets[v] = box self.mainLayout.addWidget(box) self.setLayout(self.mainLayout)
def __init__(self, label="", items=(), parent=None, labelRatio=None, boxRatio=None, toolTip="", setIndex=0): """initialize class :param label: the label of the combobox :type label: str :param items: the item list of the combobox :type items: list :param parent: the qt parent :type parent: class :param toolTip: the tooltip info to display with mouse hover :type toolTip: str :param setIndex: set the combo box value as an int - 0 is the first value, 1 is the second :type setIndex: int """ super(ComboBoxRegular, self).__init__(parent=parent) if items is None: items = [] layout = HBoxLayout(parent=None, margins=utils.marginsDpiScale(0, 0, 0, 0), spacing=utils.dpiScale(uiconstants.SREG)) # margins kwarg should be added self.box = QtWidgets.QComboBox(parent) self.box.addItems(items) self.box.setToolTip(toolTip) if label != "": self.label = Label(label, parent, toolTip) if labelRatio: layout.addWidget(self.label, labelRatio) else: layout.addWidget(self.label) if boxRatio: layout.addWidget(self.box, boxRatio) else: layout.addWidget(self.box) if setIndex: self.box.setCurrentIndex(setIndex) self.setLayout(layout) self.box.currentIndexChanged.connect(self.onItemChanged)
def iconColorized(cls, iconName, size=16, color=(255, 255, 255), overlayName=None, overlayColor=(255, 255, 255)): """ Colorizes the icon from the library expects the default icon to be white for tinting. :param iconName: the icon name from the library :type iconName: str :param size: the uniform icon size :type size: int :param color: 3 tuple for the icon color :type color: tuple(int) :return: the colorized icon :param overlayName: The name of the icon that will be overlayed on top of the original icon :param overlayColor: The colour of the overlay :rtype: QtGui.QIcon """ size = utils.dpiScale(size) iconLargest = cls.icon(iconName, -1) if not iconLargest: return iconLargest origSize = iconLargest.availableSizes()[0] pixmap = cls.colorPixmap(iconLargest.pixmap(origSize), color) # Add overlay icon if overlayName is not None: overlayIcon = cls.icon(overlayName, -1) overlayPixmap = overlayIcon.pixmap(origSize) cls.addOverlay(pixmap, overlayPixmap, overlayColor) pixmap = pixmap.scaled(QtCore.QSize(size, size), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) return QtGui.QIcon(pixmap)
def LineEdit(placeholder="", placeholderText=False, parent=None, toolTip="", editWidth=None, inputMode="string"): """Creates a simple textbox (QLineEdit) :param placeholder the default text in the text box, if placeholderText is True then it's greyed out :type placeholder: str or float or int :param placeholderText: default text is greyed out inside the textbox if true (QLineEdit) :type placeholderText: bool :param parent: the qt parent :type parent: class :param toolTip: the tool tip message on mouse over hover, extra info :type toolTip: str :param editWidth: the width of the textbox in pixels optional, None is ignored :type editWidth: int :param inputMode: restrict the user to this data entry, "string" text, "float" decimal or "int" no decimal :type inputMode: str :return textBox: the QT QLabel widget :rtype textBox: QWidget.QLabel """ textBox = QtWidgets.QLineEdit(parent=parent) # todo: STYLESHEET hardcoded color & margins here as a temp workaround, this should be in stylesheets textBox.setStyleSheet("QLineEdit {background: rgb(27, 27, 27);}") if inputMode == "float": placeholder = str(placeholder) textBox.setValidator(QtGui.QDoubleValidator()) if inputMode == "int": placeholder = int(placeholder) textBox.setValidator(QtGui.QIntValidator()) textBox.setTextMargins(*utils.marginsDpiScale(2, 2, 2, 2)) if editWidth: textBox.setFixedWidth(utils.dpiScale(editWidth)) if placeholderText: textBox.setPlaceholderText(placeholder) else: textBox.setText(placeholder) textBox.setToolTip(toolTip) return textBox
def BtnRegular(**kwargs): """Creates regular pyside button with text or an icon *Note WIP: Will fill out more options with time * should probably override ExtendedButton and not QtWidgets.QPushButton for full options :param kwargs: See the doc string from the function BtnStyle :type kwargs: dict :return qtBtn: returns a qt button widget :rtype qtBtn: object """ parent = kwargs.get("parent") text = kwargs.get("text") icon = kwargs.get("icon", (255, 255, 255)) toolTip = kwargs.get("toolTip", "") iconSize = kwargs.get("iconSize") minWidth = kwargs.get("minWidth") maxWidth = kwargs.get("maxWidth") minHeight = kwargs.get("maxHeight") maxHeight = kwargs.get("maxHeight") btn = QtWidgets.QPushButton(text, parent=parent) if icon: btn.setIcon(iconlib.icon(icon)) btn.setIconSize(QtCore.QSize(iconSize, iconSize)) """ todo: icon colorized anti aliasing is not working correctly? Icons appear thicker self.setIcon(iconlib.iconColorized(icon, size=iconSize, color=iconColor, overlayName=overlayIconName, overlayColor=overlayIconColor)) """ btn.setToolTip(toolTip) if minWidth is not None: btn.setMinimumWidth(utils.dpiScale(minWidth)) if maxWidth is not None: btn.setMaximumWidth(utils.dpiScale(maxWidth)) if minHeight is not None: btn.setMinimumHeight(utils.dpiScale(minHeight)) if maxHeight is not None: btn.setMaximumHeight(utils.dpiScale(maxHeight)) # todo: button height padding should be set in the prefs stylesheet padWidth = utils.dpiScale(3) padHeight = utils.dpiScale(4) padding = "{0} {1} {0} {1}".format(padHeight, padWidth) btn.setStyleSheet("QPushButton {padding: " + padding + ";}") return btn
def setIconPadding(self, padding): """Sets the padding for the icons of the tools and the tool menus :param padding: """ self.iconPadding = utils.dpiScale(padding)
def keyPressEvent(self, event): """ Key press event :param event: :return: """ # Use expanded tooltips if it has any if event.key() == self.ttKey: pos = self.mapFromGlobal(QtGui.QCursor.pos()) action = self.actionAt(pos) if expandedtooltip.hasExpandedTooltips(action): self._popuptooltip = expandedtooltip.ExpandedTooltipPopup(action, iconSize=utils.dpiScale(40), popupRelease=self.ttKey) self.ttKeyPressed = True super(ExtendedButtonMenu, self).keyPressEvent(event)
def iconColorizedLayered( cls, iconNames, size=16, colors=None, iconScaling=None, tintColor=None, tintComposition=QtGui.QPainter.CompositionMode_Plus, grayscale=None): """ Layers multiple icons with various colours into one qicon. Maybe can replace icon colorized :param iconNames: the icon name from the library. Allow string or list for convenience :type iconNames: list or basestring :param size: the uniform icon size :type size: int :param colors: 3 tuple for the icon color :type colors: list of tuple :return: the colorized icon :param overlayName: The name of the icon that will be overlayed on top of the original icon :param overlayColor: The colour of the overlay :rtype: QtGui.QIcon """ defaultSize = 1 size = utils.dpiScale(size) if isinstance(iconNames, basestring): iconNames = [iconNames] elif isinstance(iconNames, list): iconNames = list(iconNames) # copy if isinstance(iconScaling, list): iconScaling = list(iconScaling) # copy if not isinstance(colors, list): colors = [colors] else: colors = list(colors) # copy if iconNames is []: print "WARNING: iconNames cannot be none for iconColorizedLayered" p = QtGui.QPixmap(16, 16) p.fill(QtGui.QColor(255, 255, 255)) # Fill out the colours to match the length of iconNames if colors is None or (len(iconNames) > len(colors)): colors = colors or [] colors += [None] * (len(iconNames) - len(colors)) # Fill out the sizes to match the length of iconNames if iconScaling is None or len(iconNames) > len(iconScaling): iconScaling = iconScaling or [] iconScaling += [defaultSize] * (len(iconNames) - len(iconScaling)) iconLargest = cls.icon(iconNames.pop(0), -1) if not iconLargest: return iconLargest origSize = iconLargest.availableSizes()[0] col = colors.pop(0) scale = iconScaling.pop(0) if col is not None: pixmap = cls.colorPixmap(iconLargest.pixmap(origSize * scale), col) else: pixmap = iconLargest.pixmap(origSize * scale) # Layer the additional icons for i, name in enumerate(iconNames): if name is None: continue overlayIcon = cls.icon(name, -1) overlayPixmap = overlayIcon.pixmap(origSize * iconScaling[i]) cls.addOverlay(pixmap, overlayPixmap, colors[i]) # Tint if tintColor is not None: cls.tint(pixmap, tintColor, compositionMode=tintComposition) pixmap = pixmap.scaled( QtCore.QSize(size, size), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) # type: QtGui.QPixmap icon = QtGui.QIcon(pixmap) if grayscale: pixmap = cls.grayscale(pixmap) # todo: rough code to darken icon for alpha, this should removed and done in tint icon = QtGui.QIcon(pixmap) icon.addPixmap(icon.pixmap(size, QtGui.QIcon.Disabled)) return icon
def setHeight(self, height): """sets the size of the color widget, dpi scale handled""" self._color_widget.setFixedHeight(utils.dpiScale(height)) self._color_slider_widget.setFixedHeight(utils.dpiScale(height))