def draw_radar(self):
"""
Discards the current content and redraws all elements on the graphic scene.
"""
# decide which color to use
bg_color, line_color = Qt.black, Qt.green
self.scene.clear()
self.scene.addRect(0, 0, self.width(), self.height(), brush=QBrush(bg_color))
self._add_crosshair()
self._add_circles(self.circle_count, self.add_text_labels)
# for each measurement, draw a line
for measurement in self.measurements:
assert isinstance(measurement, Measurement)
added_time = self.added_time[measurement]
self._add_measurement(measurement.distance, measurement.angle, added_time)
# for the latest 2 measurements, draw an angle visualizer
for measurement in self.measurements[-2:]:
self._add_latest_input_line(measurement.angle)
python类QBrush()的实例源码
def set_mainwindow_palette(fanart, first_time=None):
logger.info('\n{0}: mainwindow background\n'.format(fanart))
if fanart.endswith('default.jpg'):
default_dir, default_img = os.path.split(fanart)
default_fit = os.path.join(default_dir, 'default_fit.jpg')
if not os.path.exists(default_fit):
ui.image_fit_option(fanart, default_fit, fit_size=1)
fanart = default_fit
if not os.path.isfile(fanart) or ui.keep_background_constant:
fanart = ui.default_background
if os.path.isfile(fanart):
if not ui.keep_background_constant or first_time:
palette = QtGui.QPalette()
palette.setBrush(QtGui.QPalette.Background,
QtGui.QBrush(QtGui.QPixmap(fanart)))
MainWindow.setPalette(palette)
ui.current_background = fanart
def add_cpu_sensors(self):
"""Add selected temperature sensor(s) to the "Selected CPU sensor(s)" three widget."""
items = [item for item in self.ui.treeWidgetHWMonData.selectedItems()]
# The new items should have the tree widget itself as parent
parent = self.ui.treeWidgetSelectedCPUSensors
for item in items:
sensor_item = QtWidgets.QTreeWidgetItem(parent)
sensor_item.setText(0, item.text(0))
sensor_item.setText(1, item.text(1))
sensor_item.setForeground(0, QtGui.QBrush(QtCore.Qt.blue)) # Text color blue
# Deselect all items in the HWMon tree widget after they have been added
self.ui.treeWidgetHWMonData.clearSelection()
def data(self, item, role):
# Changing color if "reserved" is True
if role == QtCore.Qt.BackgroundRole:
if item.row() % 2: # alternating background color
# dark
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 1:
return QtGui.QBrush(QtGui.QColor.fromRgb(176, 234, 153))
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 2:
return QtGui.QBrush(QtGui.QColor.fromRgb(234, 189, 190))
else:
# light
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 1:
return QtGui.QBrush(QtGui.QColor.fromRgb(198, 247, 178))
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 2:
return QtGui.QBrush(QtGui.QColor.fromRgb(250, 217, 218))
return QtSql.QSqlQueryModel.data(self, item, role)
def __init__(self, *args, **kwargs):
kwargs.setdefault('width', 2)
avatar = kwargs.setdefault('avatar', 'tuga')
self.size = kwargs.pop('size', 45)
self.validate_avatar(avatar)
self.graphics_item = cursor = QtSvg.QGraphicsSvgItem()
# Loads from turtleart.svg
cursor.setSharedRenderer(svg_renderer)
cursor.setElementId(avatar)
# Define local transforms
rect = cursor.sceneBoundingRect()
curr_width, curr_height = rect.width(), rect.height()
cursor.setTransform(QtGui.QTransform(
1.00, 0.00,
0.00, 1.00,
-curr_width / 2, -curr_height / 2)
)
cursor.setTransformOriginPoint(0.5 * curr_width, 0.5 * curr_height)
cursor.setScale(self.size / curr_width)
cursor.setZValue(1.0)
self.pen = QtGui.QPen(QtGui.QColor(0, 0, 0))
self.brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
super().__init__(*args, **kwargs)
def add_cpu_sensors(self):
"""Add selected temperature sensor(s) to the "Selected CPU sensor(s)" three widget."""
items = [item for item in self.treeWidgetHWMonData.selectedItems()]
# The new items should have the tree widget itself as parent
parent = self.treeWidgetSelectedCPUSensors
for item in items:
sensor_item = QtWidgets.QTreeWidgetItem(parent)
sensor_item.setText(0, item.text(0))
sensor_item.setText(1, item.text(1))
sensor_item.setForeground(0, QtGui.QBrush(QtCore.Qt.blue)) # Text color blue
# Deselect all items in the HWMon tree widget after they have been added
self.treeWidgetHWMonData.clearSelection()
def __init__(self):
self.scene = QGraphicsScene()
super().__init__(self.scene)
self.sheethandler = None # Will be set externally
self.setDragMode(QGraphicsView.RubberBandDrag)
self.emptySheet = True # Don't allow any modifications until a new sheet is created or loaded
self.backgroundPixmap = QPixmap("resources/grid.jpg")
self.bgBrush = QBrush(self.backgroundPixmap)
self.scene.setBackgroundBrush(self.bgBrush)
self.modman = ModuleManager()
self.initnode = None
self.loopnode = None
#self.newSheet()
#self.loadSheet(json.loads("""{"loopnode":"85a1abbd6d86462bbdad9639086b503e","85a1abbd6d86462bbdad9639086b503e":{"inputs":[],"nodename":"drluke.builtin.Loop","pos":[0,144],"outputs":[[]]},"52667c109d734f8883c74cf1a659b675":{"inputs":[],"nodename":"drluke.builtin.Init","pos":[0,0],"outputs":[[]]},"initnode":"52667c109d734f8883c74cf1a659b675"}"""))
#self.loadRelationship(json.loads("""{"loopnode":"4e742e8ccb554213a9efe10431400637","c1e809fe45f340bfa1e68ed0a5429fb0":{"outputs":[[],[]],"pos":[431,108],"inputs":[[["dbb2a2812a4d42209e6b7aa635fca477",0]],[]],"nodename":"drluke.testmodule.TestNode"},"dbb2a2812a4d42209e6b7aa635fca477":{"outputs":[[["c1e809fe45f340bfa1e68ed0a5429fb0",0]],[]],"pos":[187,85],"inputs":[[["d7e6f0fe49fd4c598fdd4503bcffbd9c",0],["4e742e8ccb554213a9efe10431400637",0]],[]],"nodename":"drluke.testmodule.TestNode"},"d7e6f0fe49fd4c598fdd4503bcffbd9c":{"outputs":[[["dbb2a2812a4d42209e6b7aa635fca477",0]]],"pos":[0,0],"inputs":[],"nodename":"drluke.builtin.Init"},"4e742e8ccb554213a9efe10431400637":{"outputs":[[["dbb2a2812a4d42209e6b7aa635fca477",0]]],"pos":[0,200],"inputs":[],"nodename":"drluke.builtin.Loop"},"initnode":"d7e6f0fe49fd4c598fdd4503bcffbd9c"}"""))
def asama_ciz(asama,tum_asama):
#Amac?m?z pencerenin üzerinde gözüken ad?m k?sm? için gerekli resmi olu?turmak
resim = QImage(950,10,QImage.Format_RGB32)
boyayici = QPainter()
boyayici.begin(resim)
mavi_kalem = QPen(QColor("#00bbf2"))
mavi_firca = QBrush(QColor("#00bbf2"))
beyaz_kalem = QPen(QColor("#ffffff"))
beyaz_firca = QBrush(QColor("#ffffff"))
boyayici.setPen(beyaz_kalem)
boyayici.setBrush(beyaz_firca)
boyayici.drawRect(0,0,950,10)
boyayici.setPen(mavi_kalem)
boyayici.setBrush(mavi_firca)
en_hesabi = (asama/tum_asama)*950
boyayici.drawRect(0,0,int(en_hesabi),10)
boyayici.end()
return resim
def draw_progress_bar(plex_item, pixmap, height=6):
"""draw a progress indicator on the bottom of pixmap with height pixels"""
if not hasattr(plex_item, 'in_progress'):
return
if not plex_item.in_progress:
return
progress_color = QtGui.QColor(204, 123, 25)
progress = plex_item.view_offset / max(1, plex_item.duration)
p = QtGui.QPainter(pixmap)
rect = p.window()
progress_rect = QtCore.QRect(rect.bottomLeft() - QtCore.QPoint(0, height),
rect.bottomRight())
progress_fill = QtCore.QRect(progress_rect)
progress_fill.setWidth(rect.width() * progress)
p.fillRect(progress_rect, QtGui.QBrush(QtCore.Qt.black))
p.fillRect(progress_fill, QtGui.QBrush(progress_color))
def draw_unwatched_indicator(plex_item, pixmap, size=0.20):
"""draw a triangle on the top right of pixmap"""
if not hasattr(plex_item, 'watched') and not hasattr(plex_item, 'in_progress'):
return
if plex_item.watched or plex_item.in_progress:
return
p = QtGui.QPainter(pixmap)
rect = p.window()
top_right = rect.topRight()
size = pixmap.height() * size
color = QtGui.QColor(204, 123, 25)
triangle = QtGui.QPolygon([top_right, top_right - QtCore.QPoint(size, 0),
top_right + QtCore.QPoint(0, size)])
p.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 120)), 6))
p.drawLine(triangle.point(1), triangle.point(2))
p.setBrush(QtGui.QBrush(color))
p.setPen(color)
p.drawPolygon(triangle)
def paint(
self,
painter: QPainter,
option: QStyleOptionGraphicsItem,
widget: QWidget):
pen = QPen()
pen.setWidth(3)
painter.setRenderHint(QPainter.Antialiasing)
pen.setColor(QColor(61, 61, 61, 255))
painter.setPen(pen)
painter.setBrush(QBrush(QColor(61, 61, 61, 255), Qt.SolidPattern))
painter.drawRect(
QRectF(-self.maxWidth / 2, -10, self.maxWidth, 20))
painter.setBrush(QBrush(QColor(240, 217, 108, 255), Qt.SolidPattern))
painter.drawRect(
QRectF(-self.maxWidth / 2, -10, self.displayWidth, 20))
path = QPainterPath()
path.addText(-self.maxWidth / 2, 35, QFont('monospace', 18, QFont.Bold), f'{self.name} Lv.{self.level} Exp. {self.actualExperience:{len(str(self.maxExperience))}}/{self.maxExperience}')
# pen.setColor(Qt.white)
pen.setWidth(2)
painter.setPen(pen)
painter.setBrush(QBrush(QColor(0, 0, 0, 61), Qt.SolidPattern))
painter.drawPath(path)
def paint(
self,
painter: QPainter,
option: QStyleOptionGraphicsItem,
widget: QWidget):
pen = QPen()
pen.setWidth(1)
painter.setRenderHint(QPainter.Antialiasing)
pen.setColor(QColor(81, 81, 81, 255))
painter.setPen(pen)
painter.setBrush(QBrush(QColor(81, 81, 81, 255), Qt.SolidPattern))
path = QPainterPath()
path.addText(
-self.width,
self.height,
QFont('monospace', 13, QFont.PreferNoHinting),
self.text)
painter.drawPath(path)
def paint(
self,
painter: QPainter,
option: QStyleOptionGraphicsItem,
widget: QWidget):
pen = QPen()
pen.setWidth(1)
painter.setRenderHint(QPainter.Antialiasing)
pen.setColor(QColor(81, 81, 81, 255))
painter.setPen(pen)
painter.setBrush(QBrush(QColor(81, 81, 81, 255), Qt.SolidPattern))
for i, score in enumerate(self.scores):
path = QPainterPath()
path.addText(
-self.width,
14 + i * 16,
QFont('monospace', 13, QFont.PreferNoHinting),
f'{score.score:6}[{score.level:2}] {score.hero_name}')
painter.drawPath(path)
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(QColor(127, 127, 127, 127)))
painter.setPen(QPen(Qt.NoPen))
for i in range(6):
if int(self.counter / 10) % 6 == i:
factor = self.counter % 10
if factor >= 5:
factor = 5 - (self.counter % 5)
painter.setBrush(QBrush(QColor(95 + factor * 32, 127, 127)))
else:
painter.setBrush(QBrush(QColor(127, 127, 127)))
painter.drawEllipse(
self.width() / 2 + 30 * math.cos(2 * math.pi * i / 6.0) - 10,
self.height() / 2 + 30 * math.sin(2 * math.pi * i / 6.0) - 10,
20, 20)
painter.end()
def paint(self, painter, option, index):
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
size = min(option.rect.width(), option.rect.height())
brightness = index.model().data(index, Qt.DisplayRole)
radius = (size/2.0) - (brightness/255.0 * size/2.0)
if radius == 0.0:
return
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
if option.state & QStyle.State_Selected:
painter.setBrush(option.palette.highlightedText())
else:
painter.setBrush(QBrush(Qt.black))
painter.drawEllipse(QRectF(
option.rect.x() + option.rect.width()/2 - radius,
option.rect.y() + option.rect.height()/2 - radius,
2*radius, 2*radius))
painter.restore()
def __init__(self, parent=None):
super(SvgView, self).__init__(parent)
self.renderer = SvgView.Native
self.svgItem = None
self.backgroundItem = None
self.outlineItem = None
self.image = QImage()
self.setScene(QGraphicsScene(self))
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
self.setDragMode(QGraphicsView.ScrollHandDrag)
self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
# Prepare background check-board pattern.
tilePixmap = QPixmap(64, 64)
tilePixmap.fill(Qt.white)
tilePainter = QPainter(tilePixmap)
color = QColor(220, 220, 220)
tilePainter.fillRect(0, 0, 32, 32, color)
tilePainter.fillRect(32, 32, 32, 32, color)
tilePainter.end()
self.setBackgroundBrush(QBrush(tilePixmap))
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(Qt.white))
painter.translate(66, 66)
painter.save()
self.transformPainter(painter)
self.drawShape(painter)
painter.restore()
self.drawOutline(painter)
self.transformPainter(painter)
self.drawCoordinates(painter)
def paintEvent(self, event):
background = QRadialGradient(QPointF(self.rect().topLeft()), 500,
QPointF(self.rect().bottomRight()))
background.setColorAt(0, self.backgroundColor1)
background.setColorAt(1, self.backgroundColor2)
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(background))
painter.setPen(self.pen)
for bubble in self.bubbles:
if QRectF(bubble.position - QPointF(bubble.radius, bubble.radius),
QSizeF(2*bubble.radius, 2*bubble.radius)).intersects(QRectF(event.rect())):
bubble.drawBubble(painter)
if self.newBubble:
self.newBubble.drawBubble(painter)
painter.end()
def paint(self, painter, option, index):
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
size = min(option.rect.width(), option.rect.height())
brightness = index.model().data(index, Qt.DisplayRole)
radius = (size/2.0) - (brightness/255.0 * size/2.0)
if radius == 0.0:
return
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
if option.state & QStyle.State_Selected:
painter.setBrush(option.palette.highlightedText())
else:
painter.setBrush(QBrush(Qt.black))
painter.drawEllipse(QRectF(
option.rect.x() + option.rect.width()/2 - radius,
option.rect.y() + option.rect.height()/2 - radius,
2*radius, 2*radius))
painter.restore()
def __init__(self, parent=None):
super(SvgView, self).__init__(parent)
self.renderer = SvgView.Native
self.svgItem = None
self.backgroundItem = None
self.outlineItem = None
self.image = QImage()
self.setScene(QGraphicsScene(self))
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
self.setDragMode(QGraphicsView.ScrollHandDrag)
self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
# Prepare background check-board pattern.
tilePixmap = QPixmap(64, 64)
tilePixmap.fill(Qt.white)
tilePainter = QPainter(tilePixmap)
color = QColor(220, 220, 220)
tilePainter.fillRect(0, 0, 32, 32, color)
tilePainter.fillRect(32, 32, 32, 32, color)
tilePainter.end()
self.setBackgroundBrush(QBrush(tilePixmap))
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(Qt.white))
painter.translate(66, 66)
painter.save()
self.transformPainter(painter)
self.drawShape(painter)
painter.restore()
self.drawOutline(painter)
self.transformPainter(painter)
self.drawCoordinates(painter)
def paintEvent(self, event):
background = QRadialGradient(QPointF(self.rect().topLeft()), 500,
QPointF(self.rect().bottomRight()))
background.setColorAt(0, self.backgroundColor1)
background.setColorAt(1, self.backgroundColor2)
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(event.rect(), QBrush(background))
painter.setPen(self.pen)
for bubble in self.bubbles:
if QRectF(bubble.position - QPointF(bubble.radius, bubble.radius),
QSizeF(2*bubble.radius, 2*bubble.radius)).intersects(QRectF(event.rect())):
bubble.drawBubble(painter)
if self.newBubble:
self.newBubble.drawBubble(painter)
painter.end()
def paint(self, painter, option, widget):
painter.setClipRect(option.exposedRect)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
if self.isSelected():
painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 92, 196, 240)))
painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1))
else:
painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 92, 196, 120)))
painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 1))
painter.drawRoundedRect(self.itemRect, 4 * (globals.TileWidth / 16), 4 * (globals.TileWidth / 16))
painter.setFont(self.font)
painter.drawText(self.itemRect, Qt.AlignCenter, str(self.type))
def color_oldDB_sections(self, old_section, intg_section, combo_section):
"""display old sections in red color.
Args:
old_section(str): Old sections from IS 808 1984
intg_section(str): Revised sections from IS 808 2007
combo_section(QcomboBox): Beam/Column dropdown list
Returns:
"""
for col in old_section:
if col in intg_section:
indx = intg_section.index(str(col))
combo_section.setItemData(indx, QBrush(QColor("red")), Qt.TextColorRole)
duplicate = [i for i, x in enumerate(intg_section) if intg_section.count(x) > 1]
for i in duplicate:
combo_section.setItemData(i, QBrush(QColor("red")), Qt.TextColorRole)
def color_oldDB_sections(self, old_section, intg_section, combo_section):
"""display old sections in red color.
Args:
old_section(str): Old sections from IS 808 1984
intg_section(str): Revised sections from IS 808 2007
combo_section(QcomboBox): Beam/Column dropdown list
Returns:
"""
for col in old_section:
if col in intg_section:
indx = intg_section.index(str(col))
combo_section.setItemData(indx, QBrush(QColor("red")), Qt.TextColorRole)
duplicate = [i for i, x in enumerate(intg_section) if intg_section.count(x) > 1]
for i in duplicate:
combo_section.setItemData(i, QBrush(QColor("red")), Qt.TextColorRole)
def color_oldDB_sections(self, old_section, intg_section, combo_section):
"""display old sections in red color.
Args:
old_section(str): Old sections from IS 808 1984
intg_section(str): Revised sections from IS 808 2007
combo_section(QcomboBox): Beam/Column dropdown list
Returns:
"""
for col in old_section:
if col in intg_section:
indx = intg_section.index(str(col))
combo_section.setItemData(indx, QBrush(QColor("red")), Qt.TextColorRole)
duplicate = [i for i, x in enumerate(intg_section) if intg_section.count(x) > 1]
for i in duplicate:
combo_section.setItemData(i, QBrush(QColor("red")), Qt.TextColorRole)
def color_oldDB_sections(self, old_section, intg_section, combo_section):
"""display old sections in red color.
Args:
old_section(str): Old sections from IS 808 1984
intg_section(str): Revised sections from IS 808 2007
combo_section(QcomboBox): Beam/Column dropdown list
Returns:
"""
for col in old_section:
if col in intg_section:
indx = intg_section.index(str(col))
combo_section.setItemData(indx, QBrush(QColor("red")), Qt.TextColorRole)
duplicate = [i for i, x in enumerate(intg_section) if intg_section.count(x) > 1]
for i in duplicate:
combo_section.setItemData(i, QBrush(QColor("red")), Qt.TextColorRole)
def set_colors(self, changed='66d9ef', unchanged='d2d2d2', default='ffffff', select='a9c5ff'):
'''Sets the colors associated with the various properties.
Args:
changed (:obj:`str`): Change color, default: '66d9ef'
unchanged (:obj:`str`): Unchanged color, default: 'd2d2d2'
default (:obj:`str`): Default color, default: 'ffffff'
select (:obj:`str`): Selected color, default: 'a9c5ff'
'''
colors = [changed, unchanged, default, select]
if None in [re.match('^[a-fA-F0-9]{6}$', x) for x in colors]:
# Invalid color provided
return
self.colors = []
for c in colors:
r, g, b = int(c[:2], 16), int(c[2:4], 16), int(c[-2:], 16)
self.colors.append(QtGui.QBrush(QtGui.QColor.fromRgb(r, g, b)))
def load_image(self, image):
"""
Call this to load a new image from the provide QImage into
this HomographyView's scene. The image's top left corner will
be placed at (0,0) in the scene.
"""
self.scene_image = image
new_scene = HomographyScene(self)
pmap = QtGui.QPixmap().fromImage(image)
pmapitem = new_scene.addPixmap(pmap)
new_scene.register_pixmap(pmapitem)
new_scene.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0)))
self.setScene(new_scene)
self.fitInView(0, 0, pmap.width(), pmap.height(), Qt.KeepAspectRatio)
self.show()
self.image_loaded = True
def __init__(self, parent):
super(HomographyScene, self).__init__(parent)
self.points = []
self.main_pixmap_item = None # Either None or a QGraphicsPixmapItem representing the loaded image
# Point configuration
self.point_rad = 12 # Radius, in pixels
self.point_pen_color = QtGui.QColor(255, 74, 13, 230) # R, G, B, A
self.point_pen = QtGui.QPen(self.point_pen_color, 6)
self.point_brush_color = QtGui.QColor(195, 13, 255, 20) # R, G, B, A
self.point_brush = QtGui.QBrush(self.point_brush_color)
self.point_selected = False
self.selected_point = None
font = QtGui.QFont()
font.setPixelSize(48)
font.setBold(True)
self.label_font = font
self.label_pen_color = QtGui.QColor(0, 0, 0) # R, G, B
self.label_pen = QtGui.QPen(self.label_pen_color, 2)
self.label_brush_color = QtGui.QColor(255, 255, 255) # R, G, B
self.label_brush = QtGui.QBrush(self.label_brush_color)