def __init__(self, parent, delegate): QWidget.__init__(self, parent) self.delegate = delegate self.emitted = False self.ui = Ui_AskVerdict() self.ui.setupUi(self) # build verdict icons if not AskVerdict.icons_cache: for i in range(self.ui.comboVerdict.count()): text = str(self.ui.comboVerdict.itemText(i)) color = VERDICT_TO_ROW_COLORS.get(text[0]) pixmap = QPixmap(16, 16) pixmap.fill(Qt.transparent) if color: painter = QPainter(pixmap) painter.setPen(Qt.black) painter.setBrush(color) painter.drawEllipse(0, 0, 15, 15) painter.end() AskVerdict.icons_cache[text] = QIcon(pixmap) # set verdict icons for i in range(self.ui.comboVerdict.count()): text = str(self.ui.comboVerdict.itemText(i)) self.ui.comboVerdict.setItemIcon(i, AskVerdict.icons_cache[text]) self.ui.evaluate.clicked.connect(self.on_evaluate_clicked)
def setNameAndBrush(self, sigma, color=Qt.black): self.sigma = sigma self.setText(str(self.brushSize)) font = QFont() font.setPointSize(10) font.setBold(True) self.setFont(font) self.setForeground(color) pixmap = QPixmap(self.pixmapSize) pixmap.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing, True) painter.setPen(color) brush = QBrush(color) painter.setBrush(brush) painter.drawEllipse( QRect( self.pixmapSize.width() / 2 - self.brushSize / 2, self.pixmapSize.height() / 2 - self.brushSize / 2, self.brushSize, self.brushSize, ) ) painter.end() self.setIcon(QIcon(pixmap)) self.setTextAlignment(Qt.AlignVCenter)
def __init__(self, parent, delegate): QWidget.__init__(self, parent) self.delegate = delegate self.emitted = False self.ui = Ui_AskVerdict() self.ui.setupUi(self) # build verdict icons if not AskVerdict.icons_cache: for text in VERDICTS: color = VERDICT_TO_ROW_COLORS.get(text[0]) pixmap = QPixmap(16, 16) pixmap.fill(Qt.transparent) if color: painter = QPainter(pixmap) painter.setPen(Qt.black) painter.setBrush(color) painter.drawEllipse(0, 0, 15, 15) painter.end() AskVerdict.icons_cache[text] = QIcon(pixmap) # set combo verdict for text in ('other...', 'skip', 'retry'): self.ui.comboVerdict.addItem(AskVerdict.icons_cache[text], text) model = self.ui.comboVerdict.model() model.itemFromIndex(model.index(0, 0)).setSelectable(False) self.ui.comboVerdict.activated.connect(self.on_dropdown_item_activated) self.ui.goodVerdict.clicked.connect(self.on_good_bad_button_clicked) self.ui.goodVerdict.setIcon(AskVerdict.icons_cache["good"]) self.ui.badVerdict.clicked.connect(self.on_good_bad_button_clicked) self.ui.badVerdict.setIcon(AskVerdict.icons_cache["bad"])
def set_color(self, color): if color != self._color: self._color = color self.emit(SIGNAL("colorChanged(QColor)"), self._color) pixmap = QPixmap(self.iconSize()) pixmap.fill(color) self.setIcon(QIcon(pixmap))
def decorate_welcome_icon(icon, background_color): """Return a `QIcon` with a circle shaped background. """ welcome_icon = QIcon() sizes = [32, 48, 64, 80] background_color = NAMED_COLORS.get(background_color, background_color) background_color = QColor(background_color) grad = radial_gradient(background_color) for size in sizes: icon_pixmap = icon.pixmap(5 * size / 8, 5 * size / 8) icon_size = icon_pixmap.size() icon_rect = QRect(QPoint(0, 0), icon_size) pixmap = QPixmap(size, size) pixmap.fill(QColor(0, 0, 0, 0)) p = QPainter(pixmap) p.setRenderHint(QPainter.Antialiasing, True) p.setBrush(QBrush(grad)) p.setPen(Qt.NoPen) ellipse_rect = QRect(0, 0, size, size) p.drawEllipse(ellipse_rect) icon_rect.moveCenter(ellipse_rect.center()) p.drawPixmap(icon_rect.topLeft(), icon_pixmap) p.end() welcome_icon.addPixmap(pixmap) return welcome_icon
def data(self, index, role): if role == Qt.EditRole: row = index.row() column = index.column() return self._colors[row][column] if role == Qt.ToolTipRole: row = index.row() column = index.column() return 'Hex code: ' + self._colors[row][column] if role == Qt.DecorationRole: row = index.row() column = index.column() value = self._colors[row][column] pixmap = QPixmap(26, 26) pixmap.fill(value) icon = QIcon(pixmap) return icon if role == Qt.DisplayRole: row = index.row() column = index.column() return self._colors[row][column]
class SetupWidget(QWidget): def __init__(self): super(SetupWidget, self).__init__() self.setFixedSize(900, 600) self.field = QPixmap(self.size()) def init_view(self): field_group = QGroupBox('Field') field_layout = QVBoxLayout() field_layout.addWidget(self) field_layout.addStretch(1) field_group.setLayout(field_layout) return field_group def draw_bkgnd(self): # initialize grass self.field.fill(Qt.green) # setup painter painter = QPainter(self.field) painter.setPen(QPen(Qt.white, 3)) # draw field lines painter.drawLine(450, 0, 450, 600) painter.drawRect(0, 0, 900, 600) painter.drawRect(0, 200, 100, 200) painter.drawRect(800, 200, 100, 200) painter.drawEllipse(400, 250, 100, 100)
def requestPixmap(self, id, size, requestedSize): head = """<svg viewBox=\"0 -1 512 2\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" preserveAspectRatio=\"none\">\n""" s1 = self._callback(0) s2 = self._callback(1) beginpoly = "<polyline points=\"" def endpoly(color): return "\" style=\"fill:none;stroke:"+color+";stroke-width:0.03\"></polyline>" bytes = QByteArray(head + beginpoly + s1 + endpoly("green") + beginpoly + s2 + endpoly("red") + "</svg>") #self._iter = (self._iter + 1) % 256 #f = open('./waveforms/instantaneousWaveform%03d.svg' % self._iter, 'w') #f.write(head + beginpoly + s1 + endpoly("green") + beginpoly + s2 + endpoly("red") + "</svg>") #f.close() renderer = QSvgRenderer() worked = renderer.load(bytes) if not worked: print("SVG parse failed.") size = renderer.defaultSize() image = QPixmap(requestedSize) image.fill(QColor(0,0,0)) painter = QPainter(image) renderer.render(painter) return image
def __init__(self, parent, delegate): QWidget.__init__(self, parent) self.delegate = delegate self.emitted = False self.ui = Ui_AskVerdict() self.ui.setupUi(self) # build verdict icons if not AskVerdict.icons_cache: for i in range(self.ui.comboVerdict.count()): text = str(self.ui.comboVerdict.itemText(i)) color = VERDICT_TO_ROW_COLORS.get(text[0]) pixmap = QPixmap(16, 16) pixmap.fill(Qt.transparent) if color: painter = QPainter(pixmap) painter.setPen(Qt.black) painter.setBrush(color) painter.drawEllipse(0, 0, 15, 15) painter.end() AskVerdict.icons_cache[text] = QIcon(pixmap) # set verdict icons for i in range(self.ui.comboVerdict.count()): text = str(self.ui.comboVerdict.itemText(i)) self.ui.comboVerdict.setItemIcon(i, AskVerdict.icons_cache[text]) self.ui.evaluate.clicked.connect(self.on_evaluate_clicked)
def paintEvent(self, _): s = QToolButton.sizeHint(self) r = 0 p = QPoint() if self.direction == QBoxLayout.TopToBottom: r = 90 p = QPoint(0, -s.height()) elif self.direction == QBoxLayout.BottomToTop: r = -90 p = QPoint(-s.width(), 0) pixmap = QPixmap(s) pixmap.fill(QColor(0, 0, 0, 0)) o = QStyleOptionToolButton() self.initStyleOption(o) o.rect.setSize(s) pixpainter = QPainter() pixpainter.begin(pixmap) self.style().drawComplexControl(QStyle.CC_ToolButton, o, pixpainter, self) pixpainter.end() painter = QPainter(self) painter.rotate(r) painter.drawPixmap(p, pixmap)
def _drawIcon(self, color=Qt.black): self.setForeground(QBrush(color)) if self.isRootNode: pixmap = QPixmap(20, 20) pixmap.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap) pen = QPen(color) pen.setWidth(1) painter.setPen(pen) painter.setBrush(color) painter.setRenderHint(QPainter.Antialiasing) if not self.isExpanded: arrowRightPolygon = [ QPoint(6, 6), QPoint(6, 14), QPoint(14, 10) ] painter.drawPolygon(QPolygon(arrowRightPolygon)) else: arrowDownPolygon = [ QPoint(6, 6), QPoint(15, 6), QPoint(10, 14) ] painter.drawPolygon(QPolygon(arrowDownPolygon)) painter.end() self.setIcon(QIcon(pixmap))
def updateFilledCircle(self, s): size = s * self.zoom pixmap = QPixmap(self.width(), self.height()) pixmap.fill(Qt.transparent) #painter filled ellipse p = QPalette() painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing) brush = QBrush(p.link().color()) painter.setBrush(brush) painter.setOpacity(0.4) painter.drawEllipse( QRect(self.width() / 2 - size / 2, self.height() / 2 - size / 2, size, size)) painter.end() #painter ellipse 2 painter2 = QPainter() painter2.begin(pixmap) painter2.setRenderHint(QPainter.Antialiasing) pen2 = QPen(Qt.green) pen2.setWidth(1) painter2.setPen(pen2) painter2.drawEllipse( QRect(self.width() / 2 - size / 2, self.height() / 2 - size / 2, size, size)) painter2.end() self.ellipseLabel.setPixmap(QPixmap(pixmap)) self.lastSize = s
def _add_subset(self, message): """ Add a new subset to the panel """ s = message.sender width = 50 height = 50 pm = QPixmap(width, height) color = mpl_to_qt4_color(s.style.color) pm.fill(color) icon = QIcon(pm) layer = QHBoxLayout() check = QCheckBox("") check.setChecked(False) self.connect(check, SIGNAL('stateChanged(int)'), self.on_check) widget = QPushButton(icon, "") self.connect(widget, SIGNAL('clicked()'), self.on_push) layer.addWidget(check) layer.addWidget(widget) self.layout.addLayout(layer) self.subset_widgets[s] = {'layer':layer, 'widget':widget, 'check':check, 'pixmap':pm} # make sure buttons are exclusive self.check_group.addButton(check)
class EkdColorPropertie(EkdPropertie): """ Définition de la propriété correspondant à une Couleur """ def __init__(self, prop, name, value, section=None ): super(EkdColorPropertie, self).__init__(prop, name, value, EkdPropertie.COLOR, section) self.label = QLabel(name) self.widget = QFrame() self.layout = QHBoxLayout(self.widget) self.line = QLineEdit(value) self.value = value self.line.setReadOnly(True) self.layout.addWidget(self.line) self.color = QPixmap(15, 15) self.color.fill(QColor.fromRgb(int("%d" % int(self.value, 16)))) self.boutton = QPushButton(QIcon(self.color), u"") self.boutton.setFixedSize(25,25) self.layout.addWidget(self.boutton) # Quand on clique sur le boutton on défini la couleur self.connect(self.boutton, SIGNAL("clicked()"), self.updateColor) def updateColor(self): newcolor = QColorDialog.getColor(QColor.fromRgb(int("%d" % int(self.value, 16))), None )# Non supporté sous Jaunty ?? if newcolor.isValid(): self.value = str("%x" % newcolor.rgb())[2:] self.color.fill(QColor.fromRgb(int("%d" % int(self.value, 16)))) self.boutton.setIcon(QIcon(self.color)) self.line.setText(self.value) EkdConfig.set(self.section, self.id, self.value)
def data(self, index, role): if role == Qt.EditRole and index.column() == self.ColumnID.Color: return (self._elements[index.row()].brushColor(), self._elements[index.row()].pmapColor()) elif role == Qt.ToolTipRole and index.column() == self.ColumnID.Color: return ("Hex code : {}\nDouble click to change".format( self._elements[index.row()].brushColor().name())) elif role == Qt.DecorationRole and index.column() == self.ColumnID.Color: row = index.row() value = self._elements[row] if value.brushColor == value.pmapColor(): pixmap = QPixmap(_NPIXELS, _NPIXELS) pixmap.fill(value.brushColor) else: a = value.brushColor().rgba() b = value.pmapColor().rgba() img = QImage(_NPIXELS,_NPIXELS, QImage.Format_RGB32) for i in range(_NPIXELS): for j in range(0, _NPIXELS - i): img.setPixel(i, j, a) for i in range(_NPIXELS): for j in range(_NPIXELS - i, _NPIXELS): img.setPixel(i, j, b) pixmap = QPixmap.fromImage(img) icon = QIcon(pixmap) return icon else: return ListModel.data(self,index,role)
def paintEvent(self, _): s = QToolButton.sizeHint(self) r = 0 p = QPoint() if self.direction == QBoxLayout.TopToBottom: r = 90 p = QPoint(0, -s.height()) elif self.direction == QBoxLayout.BottomToTop: r = -90 p = QPoint(-s.width(), 0) pixmap = QPixmap(s) pixmap.fill(QColor(0, 0, 0, 0)) o = QStyleOptionToolButton() self.initStyleOption(o) o.rect.setSize(s) pixpainter = QPainter() pixpainter.begin(pixmap) self.style().drawComplexControl(QStyle.CC_ToolButton, o, pixpainter, self) pixpainter.end() painter = QPainter(self) painter.rotate(r) painter.drawPixmap(p, pixmap)
def updatecanvas(self, canvas): """ Update the canvas object for the legend background. """ if self._lastextent == canvas.extent(): return self._lastextent = canvas.extent() if QGis.QGIS_VERSION_INT > 20200: from qgis.core import QgsMapRendererParallelJob, QgsMapSettings settings = canvas.mapSettings() extent = settings.extent() settings.setOutputSize(self.size()) settings.setExtent(extent) #settings.setFlags(QgsMapSettings.Antialiasing | QgsMapSettings.DrawLabeling ) self.renderjob = QgsMapRendererParallelJob(settings) self.renderjob.finished.connect(self._renderimage) self.renderjob.start() else: if canvas.isDrawing(): return pixmap = QPixmap(self.size()) pixmap.fill(canvas.canvasColor()) painter = QPainter(pixmap) painter.setRenderHints(QPainter.Antialiasing) renderer = canvas.mapRenderer() renderer.render(painter) del painter self.canvasimage = pixmap.toImage() self.update()
def __updatePixmap(self): """ Update the cached shadow pixmap. """ rect_size = QSize(50, 50) left = top = right = bottom = self.radius_ # Size of the pixmap. pixmap_size = QSize(rect_size.width() + left + right, rect_size.height() + top + bottom) shadow_rect = QRect(QPoint(left, top), rect_size) pixmap = QPixmap(pixmap_size) pixmap.fill(QColor(0, 0, 0, 0)) rect_fill_color = self.palette().color(QPalette.Window) pixmap = render_drop_shadow_frame( pixmap, QRectF(shadow_rect), shadow_color=self.color_, offset=QPointF(0, 0), radius=self.radius_, rect_fill_color=rect_fill_color ) self.__shadowPixmap = pixmap self.update()
def paintEvent(self, *args): #TODO OPTIMISE FOR MULTIPLE REPETITIVE CALL super().paintEvent(*args) if self.current_silhouette is not None: # Génération du QPainter print("update started") painter = QPainter(self) # Effacer la pose précédente painter.eraseRect(self.rect()) # get x axis coordonate of the center of the player 1st on the left left_center = self.player_rect.left( ) + 0.5 * self.player_rect.width() - self.player_pixel_spacing * ( len(self.current_silhouette) - 1) * 0.5 n = len(self.current_silhouette) for k in random.sample(range(n), n): vertical_random = self.vertical_random_ratio * self.pose_hauteur * random.random( ) new_pixmap = QPixmap(self.pose_largeur, self.pose_hauteur) new_pixmap.fill(self.colors[k]) new_pixmap.setMask(self.current_silhouette[k].pixmap.scaled( self.pose_largeur, self.pose_hauteur).mask()) painter.drawPixmap( int(left_center + k * self.player_pixel_spacing - (self.pose_largeur * 0.5)), self.player_rect.top() + vertical_random, self.pose_largeur, self.pose_hauteur, new_pixmap)
def set_color(self): # couleur = QtGui.QColorDialog.getColor(QtCore.Qt.white) testqt, ok = QInputDialog.getItem(None, "Couleur", "Selection d'une couleur", self.lettersToQColor.keys(), False) if ok: # couleur = self.nameColorsToLetters[testqt] couleur = self.lettersToQColor[testqt] logger.debug(couleur) self.color = self.frenchToLetter[testqt] else: couleur = self.lettersToQColor['noir'] self.color = 'b' # self.color = str(couleur.name()) # logger.debug( couleur.name()) # self.color = self.lettersToNameColor[testqt] pixmap = QPixmap(self.pushButton_color.size()) # pixmap.fill(QColor(self.color)) pixmap.fill(couleur) icon = QIcon(pixmap) self.pushButton_color.setIcon(icon) # logger.debug( QColor(self.color) ) # self.pushButton_color.setStyleSheet("background-color: " + self.color ) # palette = QtGui.QPalette() # palette.setColor(QtGui.QPalette.ButtonText, self.lettersToQColor[testqt]) # palette.setColor(10, couleur) # self.pushButton_color.setPalette(palette) self.emit(SIGNAL("colorChanged"))
def updateCircle(self, s): size = s * self.zoom pixmap = QPixmap(self.width(), self.height()) pixmap.fill(Qt.transparent) #painter ellipse 1 painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing) pen = QPen(Qt.red) pen.setWidth(3) painter.setPen(pen) brush = QBrush(Qt.green) painter.setBrush(brush) painter.drawEllipse( QRect(self.width() / 2 - size / 2, self.height() / 2 - size / 2, size, size)) painter.end() #painter ellipse 2 painter2 = QPainter() painter2.begin(pixmap) painter2.setRenderHint(QPainter.Antialiasing) pen2 = QPen(Qt.green) pen2.setStyle(Qt.DotLine) pen2.setWidth(3) painter2.setPen(pen2) painter2.drawEllipse( QRect(self.width() / 2 - size / 2, self.height() / 2 - size / 2, size, size)) painter2.end() self.ellipseLabel.setPixmap(QPixmap(pixmap)) self.lastSize = s
def setNameAndBrush(self, sigma, color=Qt.black): self.sigma = sigma self.setText( decode_to_qstring("σ=%.1fpx" % self.sigma, "utf-8") ) # This file is encoded as utf-8, so this string should be decoded as such. total_window = 1 + 2 * int(self.sigma * self.window_size + 0.5) self.setToolTip("sigma = {:.1f} pixels, window diameter = {:.1f}".format(self.sigma, total_window)) font = QFont() font.setPointSize(10) font.setBold(True) self.setFont(font) self.setForeground(color) pixmap = QPixmap(self.pixmapSize) pixmap.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing, True) painter.setPen(color) brush = QBrush(color) painter.setBrush(brush) painter.drawEllipse( QRect( self.pixmapSize.width() / 2 - self.brushSize / 2, self.pixmapSize.height() / 2 - self.brushSize / 2, self.brushSize, self.brushSize, ) ) painter.end() self.setIcon(QIcon(pixmap)) self.setTextAlignment(Qt.AlignVCenter)
def decorate_welcome_icon(icon, background_color): """Return a `QIcon` with a circle shaped background. """ welcome_icon = QIcon() sizes = [32, 48, 64, 80] background_color = NAMED_COLORS.get(background_color, background_color) background_color = QColor(background_color) grad = radial_gradient(background_color) for size in sizes: icon_pixmap = icon.pixmap(5 * size / 8, 5 * size / 8) icon_size = icon_pixmap.size() icon_rect = QRect(QPoint(0, 0), icon_size) pixmap = QPixmap(size, size) pixmap.fill(QColor(0, 0, 0, 0)) p = QPainter(pixmap) p.setRenderHint(QPainter.Antialiasing, True) p.setBrush(QBrush(grad)) p.setPen(Qt.NoPen) ellipse_rect = QRect(0, 0, size, size) p.drawEllipse(ellipse_rect) icon_rect.moveCenter(ellipse_rect.center()) p.drawPixmap(icon_rect.topLeft(), icon_pixmap) p.end() welcome_icon.addPixmap(pixmap) return welcome_icon
def colorIcon(color): r, g, b = color qcolor = QColor(r, g, b) size = QSize(22,22) pixmap = QPixmap(size) pixmap.fill(qcolor) return QIcon(pixmap)
def updateFilledCircle(self, s): size = s * self.zoom pixmap = QPixmap(self.width(), self.height()) pixmap.fill(Qt.transparent) #painter filled ellipse p = QPalette() painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing) brush = QBrush(p.link().color()) painter.setBrush(brush) painter.setOpacity(0.4) painter.drawEllipse(QRect(self.width()/2 - size/2, self.height()/2 - size/2, size, size)) painter.end() #painter ellipse 2 painter2 = QPainter() painter2.begin(pixmap) painter2.setRenderHint(QPainter.Antialiasing) pen2 = QPen(Qt.green) pen2.setWidth(1) painter2.setPen(pen2) painter2.drawEllipse(QRect(self.width()/2 - size/2, self.height()/2 - size/2, size, size)) painter2.end() self.ellipseLabel.setPixmap(QPixmap(pixmap)) self.lastSize = s
def updateCircle(self, s): size = s * self.zoom pixmap = QPixmap(self.width(), self.height()) pixmap.fill(Qt.transparent) #painter ellipse 1 painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing) pen = QPen(Qt.red) pen.setWidth(3) painter.setPen(pen) brush = QBrush(Qt.green) painter.setBrush(brush) painter.drawEllipse(QRect(self.width()/2 - size/2, self.height()/2 - size/2, size, size)) painter.end() #painter ellipse 2 painter2 = QPainter() painter2.begin(pixmap) painter2.setRenderHint(QPainter.Antialiasing) pen2 = QPen(Qt.green) pen2.setStyle(Qt.DotLine) pen2.setWidth(3) painter2.setPen(pen2) painter2.drawEllipse(QRect(self.width()/2 - size/2, self.height()/2 - size/2, size, size)) painter2.end() self.ellipseLabel.setPixmap(QPixmap(pixmap)) self.lastSize = s
def colorIcon(color): r, g, b = color qcolor = QColor(r, g, b) size = QSize(22, 22) pixmap = QPixmap(size) pixmap.fill(qcolor) return QIcon(pixmap)
def show(cursor, pos=None, num_lines=6): """Displays a tooltip showing part of the cursor's Document. If the cursor has a selection, those blocks are displayed. Otherwise, num_lines lines are displayed. If pos is not given, the global mouse position is used. """ block = cursor.document().findBlock(cursor.selectionStart()) c2 = QTextCursor(block) if cursor.hasSelection(): c2.setPosition(cursor.selectionEnd(), QTextCursor.KeepAnchor) c2.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor) else: c2.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor, num_lines) data = textformats.formatData('editor') doc = QTextDocument() font = QFont(data.font) font.setPointSizeF(font.pointSizeF() * .8) doc.setDefaultFont(font) doc.setPlainText(c2.selection().toPlainText()) if metainfo.info(cursor.document()).highlighting: highlighter.highlight(doc, state=tokeniter.state(block)) size = doc.size().toSize() + QSize(8, -4) pix = QPixmap(size) pix.fill(data.baseColors['background']) doc.drawContents(QPainter(pix)) label = QLabel() label.setPixmap(pix) label.setStyleSheet("QLabel { border: 1px solid #777; }") label.resize(size) widgets.customtooltip.show(label, pos)
def set_color(self, color): if color != self._color: self._color = color self.emit(SIGNAL("colorChanged(QColor)"), self._color) pixmap = QPixmap(self.iconSize()) pixmap.fill(color) self.setIcon(QIcon(pixmap))
def updatecanvas(self, canvas): """ Update the canvas object for the legend background. """ if self._lastextent == canvas.extent(): return self._lastextent = canvas.extent() if QGis.QGIS_VERSION_INT > 20200: from qgis.core import QgsMapRendererParallelJob, QgsMapSettings settings = canvas.mapSettings() extent = settings.extent() settings.setOutputSize(self.size()) settings.setExtent(extent) #settings.setFlags(QgsMapSettings.Antialiasing | QgsMapSettings.DrawLabeling ) self.renderjob = QgsMapRendererParallelJob(settings) self.renderjob.finished.connect(self._renderimage) self.renderjob.start() else: if canvas.isDrawing(): return pixmap = QPixmap(self.size()) pixmap.fill(canvas.canvasColor()) painter = QPainter(pixmap) painter.setRenderHints(QPainter.Antialiasing) renderer = canvas.mapRenderer() renderer.render(painter) del painter self.canvasimage = pixmap.toImage() self.update()
def _colorChanged(self, color): pix = QPixmap(22, 22) pix.fill(color) self._highlightIcon = QIcon(pix) self._highlightAction.setIcon(self._highlightIcon) self._setFilterType(FilterType.Highlight) self.clauseChanged.emit(self._filterIndex)
def pixmapFromSvg(self, pmapSize=None, withBorders=None): """returns a pixmap with default size as given in SVG and optional borders/shadows""" if withBorders is None: withBorders = Preferences.showShadows if withBorders: wantSize = self.tileset.tileSize.toSize() else: wantSize = self.tileset.faceSize.toSize() if not pmapSize: pmapSize = wantSize result = QPixmap(pmapSize) result.fill(Qt.transparent) painter = QPainter(result) if not painter.isActive(): logException('painter is not active. Wanted size: %s' % str(pmapSize)) try: xScale = float(pmapSize.width()) / wantSize.width() yScale = float(pmapSize.height()) / wantSize.height() except ZeroDivisionError: xScale = 1 yScale = 1 if not withBorders: painter.scale(*self.tileset.tileFaceRelation()) painter.translate(-self.facePos()) renderer = self.tileset.renderer() renderer.render(painter, self.elementId()) painter.resetTransform() self._drawDarkness(painter) if self.showFace(): faceSize = self.tileset.faceSize.toSize() faceSize = QSize(faceSize.width() * xScale, faceSize.height() * yScale) painter.translate(self.facePos()) renderer.render(painter, self.tileset.svgName[self.tile.element.lower()], QRectF(QPointF(), QSizeF(faceSize))) return result
def set_color(self): # couleur = QtGui.QColorDialog.getColor(QtCore.Qt.white) testqt, ok = QInputDialog.getItem(None, "Couleur", "Selection d'une couleur", LETTERSTOQCOLOR.keys(), False) if ok: # couleur = self.nameColorsToLetters[testqt] couleur = LETTERSTOQCOLOR[testqt] logger.debug(couleur) self.color = FRENCHTOLETTER[testqt] else: couleur = LETTERSTOQCOLOR['noir'] self.color = 'b' # self.color = str(couleur.name()) # logger.debug( couleur.name()) # self.color = self.lettersToNameColor[testqt] pixmap = QPixmap(self.pushButton_color.size()) # pixmap.fill(QColor(self.color)) pixmap.fill(couleur) icon = QIcon(pixmap) self.pushButton_color.setIcon(icon) # logger.debug( QColor(self.color) ) # self.pushButton_color.setStyleSheet("background-color: " + self.color ) # palette = QtGui.QPalette() # palette.setColor(QtGui.QPalette.ButtonText, self.lettersToQColor[testqt]) # palette.setColor(10, couleur) # self.pushButton_color.setPalette(palette) self.emit(SIGNAL("redraw()"))
def updateScene(self): ''' Clear the displayed scene using self.__lastclearcolor, then draw the scaled current image. ''' # get the scaled scene size labelwidth = int(self.__scalefactor * self.__scenewidth + 0.5) labelheight = int(self.__scalefactor * self.__sceneheight + 0.5) # Create the new pixmap for the label to display newpixmap = QPixmap(labelwidth, labelheight) newpixmap.fill(self.__lastclearcolor) if self.__sceneimage != None: # Draw the scaled image to the pixmap mypainter = QPainter(newpixmap) trgrect = QRectF(0.0, 0.0, float(labelwidth), float(labelheight)) srcrect = QRectF(0.0, 0.0, float(self.__scenewidth), float(self.__sceneheight)) mypainter.drawImage(trgrect, self.__sceneimage, srcrect, Qt.AutoColor) mypainter.end() # Assign the new pixmap to the label self.__label.setPixmap(newpixmap) # set the label size and values # so the scrollarea knows of the new size self.__label.setMinimumSize(labelwidth, labelheight) self.__label.resize(labelwidth, labelheight) # update the label from the new pixmap self.__label.update()
def __init__(self, name, x, y, points, abs = None, color = None): QWidget.__init__(self) self.setupUi(self) self.name = name self.lineEdit_curve_name.setText(name) logger.debug("from curve: {} {}".format(x, y)) self.coordinates = "[x=" + str(x) + ", y=" + str(y) + "]" self.label_coordinates.setText(self.coordinates) if color is None: logger.debug("len(colors): {}".format(len(COLORS))) color = COLORS[ random.randint(0, len(COLORS) - 1) ] logger.debug("color from creation courbe: {}".format(color)) self.color = color if abs: self.abs = abs else: self.abs = None pixmap = QPixmap(self.pushButton_color.size()) pixmap.fill(QColor(LETTERSTONAMECOLOR[self.color])) icon = QIcon(pixmap) self.pushButton_color.setIcon(icon) self.points = points # self.connect(self.lineEdit_curve_name, SIGNAL("textChanged(str)"), self, SIGNAL("curveTitleChanged(str)")) self.connect(self.lineEdit_curve_name, SIGNAL("editingFinished()"), self.set_name) self.connect(self.pushButton_color, SIGNAL("clicked()"), self.set_color) self.connect(self.pushButton_delete_curve, SIGNAL("clicked()"), self, SIGNAL("deleteCurve()")) self.connect(self.checkBox_curve_visible, SIGNAL("stateChanged(int)"), self.change_state)
def getmap(self): if self.canvas: pixmap = QPixmap(self.canvas.size()) pixmap.fill(self.canvas.canvasColor()) painter = QPainter(pixmap) renderer = self.canvas.mapRenderer() renderer.render(painter) del painter self.scribbleArea.addMap(pixmap)
def make_qicon(hicon): width = 16 height = 16 if valid_handle(hicon): return QPixmap.fromWinHICON(hicon).scaled(width, height) else: ret = QPixmap(width, height) ret.fill(Qt.transparent) return ret
def __init__(self, num, parent=None): super(ViewedNoteIcon, self).__init__(parent) pixmap = QPixmap(16, 16) pixmap.fill(Qt.cyan) rect = QRect(0, 0, 16, 16) painter = QPainter(pixmap) painter.drawText(rect, Qt.AlignHCenter | Qt.AlignVCenter, str(num)) self.addPixmap(pixmap) del painter
def __init__(self, num, parent=None): super(ViewedNoteIcon, self).__init__(parent) pixmap = QPixmap(16, 16) pixmap.fill(Qt.cyan) rect = QRect(0, 0, 16, 16) painter = QPainter(pixmap) painter.drawText(rect, Qt.AlignHCenter | Qt.AlignVCenter, str(num)) self.addPixmap(pixmap) del painter
def getmap(self): if self.canvas: pixmap = QPixmap(self.canvas.size()) pixmap.fill(self.canvas.canvasColor()) painter = QPainter(pixmap) renderer = self.canvas.mapRenderer() renderer.render(painter) del painter self.scribbleArea.addMap(pixmap)
def setFeatureVHeader(self, feature): self.feature = feature self.vHeaderName = feature.name self.setText(self.vHeaderName) # self.featureID = feature.id pixmap = QPixmap(20, 20) pixmap.fill(Qt.transparent) self.setIcon(QIcon(pixmap))
def setFeatureVHeader(self, feature): self.feature = feature self.vHeaderName = feature.name self.setText(self.vHeaderName) # self.featureID = feature.id pixmap = QPixmap(20, 20) pixmap.fill(Qt.transparent) self.setIcon(QIcon(pixmap))
def adjust_widget(self): self.setAttribute(Qt.WA_KeyCompression,False) self.setMouseTracking(True) self.setFocus() px = QPixmap(32,32) px.fill() px.setMask(px.createHeuristicMask()) self.setCursor(QCursor(px))
def color(value, size=QSize(16, 16)): """ Creates an icon representing a QColor. @param value QIcon @param size QSize: Size of the icon to generate. @returns QIcon """ pixmap = QPixmap(size) pixmap.fill(value) return QIcon(pixmap)
def colorIcon(color, width=10, height=10): """ Creates an icon filled with specified color. @param color QColor instance @param width width of icon in pixels @param height of icon in pixels @return QIcon instance """ pixmap = QPixmap(width, height) pixmap.fill(color) return QIcon(pixmap)
def colorIcon(color, width=10, height=10): """ Creates an icon filled with specified color. @param color QColor instance @param width width of icon in pixels @param height of icon in pixels @return QIcon instance """ pixmap = QPixmap(width, height) pixmap.fill(color) return QIcon(pixmap)
def x_bitmap_opaque ( self, bitmap ): """ Returns a version of the specified bitmap with no transparency. """ dx = bitmap.width() dy = bitmap.height() opaque_bitmap = QPixmap( dx, dy ) opaque_bitmap.fill( WindowColor ) q = QPainter( opaque_bitmap ) q.drawPixmap( 0, 0, bitmap ) return opaque_bitmap
def mousePressEvent(self, event): self.x = self._xFromEventX(event) self.y = self._yFromEventY(event) cell = self.grid[self.x][self.y] color = Qt.darkGray if cell == RED: color = Qt.red elif cell == YELLOW: color = Qt.yellow pixmap = QPixmap(12, 12) pixmap.fill(color) self.setCursor(QCursor(pixmap))
def palette_pixmap(colors, size): img = QPixmap(size) img.fill(Qt.transparent) painter = QPainter(img) grad = palette_gradient(colors) grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(grad)) painter.drawRect(0, 0, size.width(), size.height()) painter.end() return img
def symbolIcon(symbol): """ Icon for a symbol. @param symbol name of symbol @return QIcon instance; transparent but valid if symbol icon not found """ icon = QIcon(':images/tickers/%s.png' % (symbol.lower(), )) if icon.pixmap(16, 16).isNull(): pixmap = QPixmap(16, 16) pixmap.fill(QColor(0, 0, 0, 0)) icon = QIcon(pixmap) return icon
def __init__(self): QTableWidgetItem.__init__(self) # init # ------------------------------------------------ self.isExpanded = True self.isRootNode = False self.feature = None self.vHeaderName = None self.children = [] pixmap = QPixmap(20, 20) pixmap.fill(Qt.transparent) self.setIcon(QIcon(pixmap))
def __init__(o, parent, pieceid, w, h, dominant_colors): QGraphicsPixmapItem.__init__(o, parent=parent) o.id = pieceid o.dominant_colors = dominant_colors o.angle_deg = 0 o.img = None o._got_image = False # create dummy pixmap, transparent pxm = QPixmap(w, h) pxm.fill(QColor(0, 0, 0, 0)) o.setPixmap(pxm) o.setTransformationMode(Qt.SmoothTransformation)
def mousePressEvent(self, event): self.x = self._xFromEventX(event) self.y = self._yFromEventY(event) cell = self.grid[self.x][self.y] color = Qt.darkGray if cell == RED: color = Qt.red elif cell == YELLOW: color = Qt.yellow pixmap = QPixmap(12, 12) pixmap.fill(color) self.setCursor(QCursor(pixmap))
def updateColor(self): iconSize = self.iconSize() width = iconSize.width() height = iconSize.height() pixmap = QPixmap(iconSize) pixmap.fill(self._color) painter = QPainter() painter.begin(pixmap) painter.setPen(QPen(QColor("#777777"))) painter.drawRect(QRect(0, 0, width - 1, height - 1)) painter.end() self.setIcon(QIcon(pixmap))
def __init__(self): QTableWidgetItem.__init__(self) # init # ------------------------------------------------ self.isExpanded = True self.isRootNode = False self.feature = None self.vHeaderName = None self.children = [] pixmap = QPixmap(20, 20) pixmap.fill(Qt.transparent) self.setIcon(QIcon(pixmap))