本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsTextItem.setDefaultTextColor方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.setDefaultTextColor方法的具体用法?Python QGraphicsTextItem.setDefaultTextColor怎么用?Python QGraphicsTextItem.setDefaultTextColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setDefaultTextColor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createImage
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
def createImage(self, transform):
if self.type == DemoTextItem.DYNAMIC_TEXT:
return None
sx = min(transform.m11(), transform.m22())
sy = max(transform.m22(), sx)
textItem = QGraphicsTextItem()
textItem.setHtml(self.text)
textItem.setTextWidth(self.textWidth)
textItem.setFont(self.font)
textItem.setDefaultTextColor(self.textColor)
textItem.document().setDocumentMargin(2)
w = textItem.boundingRect().width()
h = textItem.boundingRect().height()
image = QImage(int(w * sx), int(h * sy),
QImage.Format_ARGB32_Premultiplied)
image.fill(QColor(0, 0, 0, 0).rgba())
painter = QPainter(image)
painter.scale(sx, sy)
style = QStyleOptionGraphicsItem()
textItem.paint(painter, style, None)
return image
示例2: addWP
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
def addWP(self, wp):
if wp.command in [mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TO_ALT,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TURNS,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TIME,
mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM,
mavutil.mavlink.MAV_CMD_NAV_LAND]:
#point
rad = self.__wp_diameter * 0.5
ellipse = QGraphicsEllipseItem(wp.y - rad, -wp.x - rad,
self.__wp_diameter, self.__wp_diameter, self.__mission_layer)
ellipse.setBrush(QBrush(QColor(255, 255, 255)))
e_pen = QPen(QColor(255, 255, 255))
e_pen.setWidth(0)
ellipse.setPen(e_pen)
self.__mission_layer.addToGroup(ellipse)
#label
label = QGraphicsTextItem(str(wp.seq), self.__mission_layer)
label.setZValue(2)
label.setDefaultTextColor(Qt.white)
label.setPos(wp.y + rad, -wp.x - rad)
label.setScale(0.00002) #bit hacky -- really should scale based on
#current zoom, but I'm in a hurry.
self.__mission_layer.addToGroup(label)
label.show()
示例3: AnimatedClock
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
class AnimatedClock(QGraphicsView):
def __init__(self, parent=None):
QGraphicsView.__init__(self, parent)
self.updateSecs = 0.5
# Border
self.setLineWidth(0)
self.setFrameShape(QtWidgets.QFrame.NoFrame)
# Size
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
sizePolicy.setHeightForWidth(True)
self.setSizePolicy(sizePolicy)
# No scrollbars
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# Scene
self.scene = QGraphicsScene()
self.setScene(self.scene)
self.setBackgroundBrush(QColor("black"))
# Text of clock
self.textItem = QGraphicsTextItem()
self.textItem.color = QColor(QColor("black"))
self.textItem.setFont(QFont("Segoe UI", 80))
self.textItem.setDefaultTextColor(QColor("white"))
self.textItem.setHtml("")
self.textItem.setZValue(20)
self.scene.addItem(self.textItem)
# Start ticking
self.start()
def sizeHint(self):
return QSize(300, 150)
def start(self):
self.updateTimer = QTimer()
self.updateTimer.setInterval(self.updateSecs * 990)
self.updateTimer.timeout.connect(self.updateClock)
self.updateTimer.start()
print("Animated clock - starting")
def stop(self):
if self.updateTimer != None:
self.updateTimer.stop()
print("Animated clock - stopping")
def updateClock(self):
localtime = time.localtime()
timeString = time.strftime("%H:%M:%S", localtime)
self.textItem.setHtml(timeString)
width = self.frameGeometry().width()
self.textItem.setFont(QFont("Segoe UI", width / 8))
self.textItem.update()
def heightForWidth(self, width):
return width * .32
def keyPressEvent(self, event): #QKeyEvent
event.ignore()
示例4: showImage
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
def showImage(self):
(newImg, newImgInfo) = self.loadImage()
# return PicItem(Pixmap(QPixmap(newImg)), -1, -1, xFactor, yFactor, newImgInfo)
self.scene.clear()
imgSz = newImgInfo.imgSize
self.setSceneRect(QRectF(0,0,imgSz.width(), imgSz.height()))
pixMap = QPixmap.fromImage(newImg)
# # pixMap.setWidth(self.width())
pixMapItem = self.scene.addPixmap(pixMap)
# pixMapItem.setPos(50,50)
# self.fitInView(QRectF(0, 0, self.width(), self.height()), Qt.KeepAspectRatio)
# Add caption
caption = QGraphicsTextItem()
caption.setDefaultTextColor(QColor(255,255,255))
caption.setPos(0, self.height()*0.94)
caption.setFont(QFont("Segoe UI", 30))
caption.setTextWidth(self.width())
# caption.setPos(100, 100)
# caption.setTextWidth(1500)
# if newImgInfo.createDate is not None:
# caption.setPlainText(newImgInfo.createDate.format());
# else:
# caption.setPlainText("Image is called bananas");
# print("Tags", newImgInfo.tags)
# tagStr = ""
# for tag in newImgInfo.tags:
# if tag != "Duplicate":
# tagStr += (", " if len(tagStr) != 0 else "") + tag
# if tagStr == "":
# tagStr = "NO TAGS"
# captionStr = '<h1 style="text-align:center;width:100%">' + tagStr + '</h1>'
# if newImgInfo.createDate is not None:
# print(newImgInfo.createDate.format())
# captionStr += '<BR><h2>' + newImgInfo.createDate.format() + '</h2>'
captionStr = ""
try:
if newImgInfo.rating is not None:
for i in range(newImgInfo.rating):
captionStr += "★"
for i in range(5-newImgInfo.rating):
captionStr += "☆"
if newImgInfo.mainDate is not None:
if len(captionStr) != 0:
captionStr += " "
captionStr += newImgInfo.mainDate.strftime("%d %b %Y")
except Exception as excp:
print("StaticPhotos: Cannot set caption")
captionStr = '<div style="background-color:#000000;text-align: right;padding-right:10dp;">' + captionStr + "</div>"
print(captionStr)
caption.setHtml(captionStr)
self.scene.addItem(caption)
self.scene.update()
示例5: updateIcon
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
def updateIcon(self, id, uav_state, image_num=0):
if uav_state.get_lon() == 0.0:
#haven't received a Pose message yet
return
if id not in self.__plane_icons:
#make the plane's label first
label = QGraphicsTextItem(str(id), self.__plane_layer)
label.setZValue(2)
label.setDefaultTextColor(Qt.red)
self.__plane_layer.addToGroup(label)
label.show()
self.__plane_labels[id] = label
self.__plane_icons[id] = MapGraphicsIcon(id, label,
self.__plane_layer)
self.__plane_icons[id].centerIconAt(uav_state.get_lon(),
-uav_state.get_lat())
self.__plane_icons[id].textureIcon(self.__plane_icon_pixmaps[image_num])
#plane icons need to be drawn on top of map tiles:
self.__plane_icons[id].setZValue(1)
self.__plane_layer.addToGroup(self.__plane_icons[id])
#key 0 = last update time
self.__plane_icons[id].setData(0, 0)
#refresh:
#HACK: don't know why zooming works to refresh. Couldn't
#get scene.invalidate() nor scene.update() to work
self.onZoom(self.__current_detail_layer)
#end if
now = time.time()
#if we don't have new pose data, then we don't update the plane icon
if (self.__plane_icons[id].data(0) is None
or self.__plane_icons[id].data(0) >= uav_state.get_last_pose_update()):
return
#place icon
self.__plane_icons[id].centerIconAt(uav_state.get_lon(), -uav_state.get_lat())
#give correct heading:
quat = uav_state.get_quat()
heading = acs_math.yaw_from_quat(quat[0], quat[1], quat[2], quat[3])
self.__plane_icons[id].setHeading(heading)
#set last update time
self.__plane_icons[id].setData(0, now)
示例6: ParticipantItem
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
class ParticipantItem(QGraphicsItem):
def __init__(self, model_item: Participant, parent=None):
super().__init__(parent)
self.model_item = model_item
self.text = QGraphicsTextItem(self)
self.line = QGraphicsLineItem(self)
self.line.setPen(QPen(Qt.darkGray, 1, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
self.refresh()
def update_position(self, x_pos=-1, y_pos=-1):
if x_pos == -1:
x_pos = self.x_pos()
if y_pos == -1:
y_pos = self.line.line().y2()
self.text.setPos(x_pos - (self.text.boundingRect().width() / 2), 0)
self.line.setLine(x_pos, 30, x_pos, y_pos)
def x_pos(self):
return self.line.line().x1()
def width(self):
return self.boundingRect().width()
def refresh(self):
self.text.setPlainText("?" if not self.model_item else self.model_item.shortname)
if hasattr(self.model_item, "simulate") and self.model_item.simulate:
font = QFont()
font.setBold(True)
self.text.setFont(font)
self.text.setDefaultTextColor(Qt.darkGreen)
self.line.setPen(QPen(Qt.darkGreen, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
else:
self.text.setFont(QFont())
self.text.setDefaultTextColor(constants.LINECOLOR)
self.line.setPen(QPen(Qt.darkGray, 1, Qt.DashLine, Qt.RoundCap, Qt.RoundJoin))
def boundingRect(self):
return self.childrenBoundingRect()
def paint(self, painter, option, widget):
pass
示例7: create_map_points
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
def create_map_points(self):
self.map_points_text_items = []
self.map_points_items = []
for map_point in self.map_data.map_points:
color = QColor().fromRgb(map_point.r, map_point.g, map_point.b)
rect = QGraphicsRectItem(
QRectF(
QPointF(map_point.x, map_point.y),
QSizeF(5 / self.scale_ratio, 5 / self.scale_ratio)
)
)
rect.setPen(QPen(Qt.black, 1 / self.scale_ratio))
rect.setBrush(color)
self.map_points_items.append(rect)
text = QGraphicsTextItem(map_point.text)
text.setDefaultTextColor(color)
text.setPos(map_point.x, map_point.y)
text.setFont(QFont('Times New Roman', 8 / self.scale_ratio, 2))
self.map_points_text_items.append(text)
示例8: TcamScreen
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
#.........这里部分代码省略.........
self.display_real_image = True
if self.image_counter == 1:
self.resize(self.size())
self.scene.setSceneRect(self.pix.boundingRect())
self.update()
self.reset_zoom()
self.first_image = False
# wait for the second image
# resizeEvents, etc appear before the scene has adjusted
# to the actual image size. By waiting for the 2. image
# we circumvent this by having the first image making all
# adjustments for us. The only scenario where this will
# cause problems is triggering.
if self.is_fullscreen and self.image_counter == 2:
self.fit_view()
self.send_mouse_pixel()
# don't call repaint here
# it causes problems once the screen goes blank due to screensavers, etc
# self.repaint()
def wait_for_first_image(self):
if not self.display_real_image:
return
self.reset_zoom()
self.display_real_image = False
self.text_item = QGraphicsTextItem()
self.text_item.setDefaultTextColor(QColor("white"))
self.text_item.setPos(100, 70)
self.text_item.setPlainText("In Trigger Mode. Waiting for first image...")
bg = QPixmap(1280, 720)
bg.fill(QColor("grey"))
self.pix.setPixmap(bg)
self.image_counter += 1
self.scene.addItem(self.text_item)
def send_mouse_pixel(self):
# mouse positions start at 0
# we want the lower right corner to have the correct coordinates
# e.g. an 1920x1080 image should have the coordinates
# 1920x1080 for the last pixel
self.new_pixel_under_mouse.emit(self.pix.legal_coordinates(self.mouse_position_x,
self.mouse_position_y),
self.mouse_position_x + 1,
self.mouse_position_y + 1,
self.pix.get_color_at_position(self.mouse_position_x,
self.mouse_position_y))
def mouseMoveEvent(self, event):
mouse_position = self.mapToScene(event.pos())
self.mouse_position_x = mouse_position.x()
self.mouse_position_y = mouse_position.y()
if self.selection_area:
# adjust rect since we want to pull in all directions
# origin can well be bottom left, thus recalc
示例9: OcrArea
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
class OcrArea(QGraphicsRectItem):
## static data
resizeBorder = .0
def __init__(self, pos, size, type_, parent = None, scene = None,
areaBorder = 2, index = 0, textSize = 50):
QGraphicsRectItem.__init__(self, 0, 0, size.width(), size.height(),
parent)
self.setPos(pos)
self.newEvent = IsClicked()
self.newEvent.area = self
#self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setFlags(QGraphicsItem.ItemIsMovable |
QGraphicsItem.ItemIsFocusable |
QGraphicsItem.ItemIsSelectable)
## set index label
self.text = QGraphicsTextItem("%d" % index, self)
self.setTextSize(textSize)
## TODO: How to create constants for the type?
## (such as constants in Qt) (enum?)
self.kind = type_
pen = QPen(self.color, areaBorder, Qt.SolidLine,
Qt.RoundCap, Qt.RoundJoin)
self.setPen(pen)
# self.setAcceptsHoverEvents(True) # TODO
# self.text.setFlag(QtGui.QGraphicsItem.ItemIgnoresTransformations)
def setIndex(self, idx):
self.text.setPlainText(str(idx))
def setTextSize(self, size):
font = QFont()
font.setPointSizeF(size)
self.text.setFont(font)
def contextMenuEvent(self, event):
menu = QMenu()
removeAction = menu.addAction(QA.translate('QOcrWidget', "Remove"))
#Action = menu.addAction(self.scene().tr("Remove"))
menu.addSeparator()
textAction = menu.addAction(QA.translate('QOcrWidget', "Text"))
graphicsAction = menu.addAction(QA.translate('QOcrWidget', "Graphics"))
## verification of the type of the selection and
## setting a check box near the type that is in use
textAction.setCheckable(True)
graphicsAction.setCheckable(True)
if self.kind == 1:
textAction.setChecked(True)
elif self.kind == 2:
graphicsAction.setChecked(True)
selectedAction = menu.exec_(event.screenPos())
if selectedAction == removeAction:
self.scene().removeArea(self)
elif selectedAction == textAction:
self.kind = 1
elif selectedAction == graphicsAction:
self.kind = 2
# when the area is selected the signal "isClicked()" is raised
def mousePressEvent(self, event):
self.newEvent.isClicked.emit()
QGraphicsRectItem.mousePressEvent(self, event)
# type property
def _setType(self, type_):
self.__type = type_
if self.__type == 1:
self.color = Qt.darkGreen
else: ## TODO: else -> elif ... + else raise exception
self.color = Qt.blue
self.text.setDefaultTextColor(self.color)
pen = self.pen()
pen.setColor(self.color)
self.setPen(pen)
def _type(self):
return self.__type
kind = property(fget=_type, fset=_setType)
示例10: QGraphicsResizableRect
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsTextItem import setDefaultTextColor [as 别名]
class QGraphicsResizableRect(QGraphicsRectItem):
hoverColor = QColor(255, 0, 0) #_hovering and selection color
def __init__(self,x,y,h,w, scene=None,parent=None, editor=None):
""""
This class implements the resizable rectangle item which is dispalied on the scene
x y should be the original positions in scene coordinates
h,w are the height and the width of the rectangle
"""
self._editor = editor
QGraphicsRectItem.__init__(self,0,0,w,h,parent=parent)
self.Signaller=QGraphicsResizableRectSignaller(parent=parent)
scene.addItem(self)
#Default Appearence Properties
self._fontColor=QColor(255, 255, 255)
self._fontSize=10
self._lineWidth=1
##Note: need to do like this because the x,y of the graphics item fix the position
# of the zero relative to the scene
self.moveBy(x,y)
#Flags
self.setFlag(QGraphicsItem.ItemIsMovable,True )
self.setFlag(QGraphicsItem.ItemIsSelectable,True)
self.setFlag(QGraphicsItem.ItemSendsGeometryChanges ,True)
self.setAcceptHoverEvents(True)
self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton)
self._resizeHandles=[]
# A bit of flags
self._hovering=False
self._normalColor = QColor(0, 0, 255)
self.updateColor()
self._has_moved=False
self._selected=False
self._dbg=False
self._setupTextItem()
self._isFixed = False
self.initHandles()
self.hideHandles()
self.setToolTip("Hold CTRL to drag the box")
@property
def fontColor(self):
return self._fontColor
@pyqtSlot(int)
def setFontColor(self,color):
self._fontColor=color
self.textItem.setDefaultTextColor(color)
self.updateText(self.textItem.toPlainText())
@property
def fontSize(self):
return self._fontSize
@pyqtSlot(int)
def setFontSize(self,s):
self._fontSize=s
font=QFont()
font.setPointSize(self._fontSize)
self.textItem.setFont(font)
self.updateText(self.textItem.toPlainText())
@property
def lineWidth(self):
return self._lineWidth
@pyqtSlot(int)
def setLineWidth(self,s):
self._lineWidth=s
self.updateColor()
@property
def color(self):
return self._normalColor
@pyqtSlot(int)
def setColor(self,qcolor):
self._normalColor=qcolor
self.updateColor()
@pyqtSlot()
def _setupTextItem(self):
#Set up the text
self.textItem=QGraphicsTextItem("",parent=self)
textItem=self.textItem
font=QFont()
#.........这里部分代码省略.........