本文整理汇总了Python中PyQt5.QtWidgets.QToolTip.palette方法的典型用法代码示例。如果您正苦于以下问题:Python QToolTip.palette方法的具体用法?Python QToolTip.palette怎么用?Python QToolTip.palette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QToolTip
的用法示例。
在下文中一共展示了QToolTip.palette方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.QtWidgets import QToolTip [as 别名]
# 或者: from PyQt5.QtWidgets.QToolTip import palette [as 别名]
def paintEvent(self, evt):
"""
Protected method handling paint events.
@param evt paint event (QPaintEvent)
"""
painter = QPainter(self)
if self.__time < self.__length:
pal = QToolTip.palette()
textBackgroundColor = pal.color(QPalette.Active, QPalette.Base)
if self.__toggle:
textColor = pal.color(QPalette.Active, QPalette.Text)
else:
textColor = pal.color(QPalette.Active, QPalette.Base)
painter.setPen(textColor)
painter.setBrush(textBackgroundColor)
helpText = self.tr("Snapshot will be taken in %n seconds", "",
self.__length - self.__time)
textRect = painter.boundingRect(
self.rect().adjusted(2, 2, -2, -2),
Qt.AlignHCenter | Qt.TextSingleLine, helpText)
painter.drawText(textRect, Qt.AlignHCenter | Qt.TextSingleLine,
helpText)
示例2: paintEvent
# 需要导入模块: from PyQt5.QtWidgets import QToolTip [as 别名]
# 或者: from PyQt5.QtWidgets.QToolTip import palette [as 别名]
def paintEvent(self, evt):
"""
Protected method handling paint events.
@param evt paint event (QPaintEvent)
"""
if self.__grabbing: # grabWindow() should just get the background
return
painter = QPainter(self)
pal = QPalette(QToolTip.palette())
font = QToolTip.font()
handleColor = pal.color(QPalette.Active, QPalette.Highlight)
handleColor.setAlpha(160)
overlayColor = QColor(0, 0, 0, 160)
textColor = pal.color(QPalette.Active, QPalette.Text)
textBackgroundColor = pal.color(QPalette.Active, QPalette.Base)
painter.drawPixmap(0, 0, self.__pixmap)
painter.setFont(font)
r = QRect(self.__selection)
if not self.__selection.isNull():
grey = QRegion(self.rect())
if self.__mode == SnapshotRegionGrabber.Ellipse:
reg = QRegion(r, QRegion.Ellipse)
else:
reg = QRegion(r)
grey = grey.subtracted(reg)
painter.setClipRegion(grey)
painter.setPen(Qt.NoPen)
painter.setBrush(overlayColor)
painter.drawRect(self.rect())
painter.setClipRect(self.rect())
drawRect(painter, r, handleColor)
if self.__showHelp:
painter.setPen(textColor)
painter.setBrush(textBackgroundColor)
self.__helpTextRect = painter.boundingRect(
self.rect().adjusted(2, 2, -2, -2),
Qt.TextWordWrap, self.__helpText).translated(
-self.__desktop.x(), -self.__desktop.y())
self.__helpTextRect.adjust(-2, -2, 4, 2)
drawRect(painter, self.__helpTextRect, textColor,
textBackgroundColor)
painter.drawText(
self.__helpTextRect.adjusted(3, 3, -3, -3),
Qt.TextWordWrap, self.__helpText)
if self.__selection.isNull():
return
# The grabbed region is everything which is covered by the drawn
# rectangles (border included). This means that there is no 0px
# selection, since a 0px wide rectangle will always be drawn as a line.
txt = "{0:n}, {1:n} ({2:n} x {3:n})".format(
self.__selection.x(), self.__selection.y(),
self.__selection.width(), self.__selection.height())
textRect = painter.boundingRect(self.rect(), Qt.AlignLeft, txt)
boundingRect = textRect.adjusted(-4, 0, 0, 0)
if textRect.width() < r.width() - 2 * self.__handleSize and \
textRect.height() < r.height() - 2 * self.__handleSize and \
r.width() > 100 and \
r.height() > 100:
# center, unsuitable for small selections
boundingRect.moveCenter(r.center())
textRect.moveCenter(r.center())
elif r.y() - 3 > textRect.height() and \
r.x() + textRect.width() < self.rect().width():
# on top, left aligned
boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3))
textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3))
elif r.x() - 3 > textRect.width():
# left, top aligned
boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()))
textRect.moveTopRight(QPoint(r.x() - 5, r.y()))
elif r.bottom() + 3 + textRect.height() < self.rect().bottom() and \
r.right() > textRect.width():
# at bottom, right aligned
boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3))
textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3))
elif r.right() + textRect.width() + 3 < self.rect().width():
# right, bottom aligned
boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom()))
textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom()))
# If the above didn't catch it, you are running on a very
# tiny screen...
drawRect(painter, boundingRect, textColor, textBackgroundColor)
painter.drawText(textRect, Qt.AlignHCenter, txt)
if (r.height() > self.__handleSize * 2 and
r.width() > self.__handleSize * 2) or \
not self.__mouseDown:
self.__updateHandles()
painter.setPen(Qt.NoPen)
painter.setBrush(handleColor)
painter.setClipRegion(
#.........这里部分代码省略.........
示例3: paintEvent
# 需要导入模块: from PyQt5.QtWidgets import QToolTip [as 别名]
# 或者: from PyQt5.QtWidgets.QToolTip import palette [as 别名]
def paintEvent(self, evt):
"""
Protected method handling paint events.
@param evt paint event (QPaintEvent)
"""
if self.__grabbing: # grabWindow() should just get the background
return
painter = QPainter(self)
pal = QPalette(QToolTip.palette())
font = QToolTip.font()
handleColor = pal.color(QPalette.Active, QPalette.Highlight)
handleColor.setAlpha(160)
overlayColor = QColor(0, 0, 0, 160)
textColor = pal.color(QPalette.Active, QPalette.Text)
textBackgroundColor = pal.color(QPalette.Active, QPalette.Base)
painter.drawPixmap(0, 0, self.__pixmap)
painter.setFont(font)
pol = QPolygon(self.__selection)
if not self.__selection.boundingRect().isNull():
# Draw outline around selection.
# Important: the 1px-wide outline is *also* part of the
# captured free-region
pen = QPen(handleColor, 1, Qt.SolidLine, Qt.SquareCap,
Qt.BevelJoin)
painter.setPen(pen)
painter.drawPolygon(pol)
# Draw the grey area around the selection.
grey = QRegion(self.rect())
grey = grey - QRegion(pol)
painter.setClipRegion(grey)
painter.setPen(Qt.NoPen)
painter.setBrush(overlayColor)
painter.drawRect(self.rect())
painter.setClipRect(self.rect())
drawPolygon(painter, pol, handleColor)
if self.__showHelp:
painter.setPen(textColor)
painter.setBrush(textBackgroundColor)
self.__helpTextRect = painter.boundingRect(
self.rect().adjusted(2, 2, -2, -2),
Qt.TextWordWrap, self.__helpText).translated(
-self.__desktop.x(), -self.__desktop.y())
self.__helpTextRect.adjust(-2, -2, 4, 2)
drawPolygon(painter, self.__helpTextRect, textColor,
textBackgroundColor)
painter.drawText(
self.__helpTextRect.adjusted(3, 3, -3, -3),
Qt.TextWordWrap, self.__helpText)
if self.__selection.isEmpty():
return
# The grabbed region is everything which is covered by the drawn
# rectangles (border included). This means that there is no 0px
# selection, since a 0px wide rectangle will always be drawn as a line.
boundingRect = self.__selection.boundingRect()
txt = "{0}, {1} ({2} x {3})".format(
self.__locale.toString(boundingRect.x()),
self.__locale.toString(boundingRect.y()),
self.__locale.toString(boundingRect.width()),
self.__locale.toString(boundingRect.height())
)
textRect = painter.boundingRect(self.rect(), Qt.AlignLeft, txt)
boundingRect = textRect.adjusted(-4, 0, 0, 0)
polBoundingRect = pol.boundingRect()
if (textRect.width() <
polBoundingRect.width() - 2 * self.__handleSize) and \
(textRect.height() <
polBoundingRect.height() - 2 * self.__handleSize) and \
polBoundingRect.width() > 100 and \
polBoundingRect.height() > 100:
# center, unsuitable for small selections
boundingRect.moveCenter(polBoundingRect.center())
textRect.moveCenter(polBoundingRect.center())
elif polBoundingRect.y() - 3 > textRect.height() and \
polBoundingRect.x() + textRect.width() < self.rect().width():
# on top, left aligned
boundingRect.moveBottomLeft(
QPoint(polBoundingRect.x(), polBoundingRect.y() - 3))
textRect.moveBottomLeft(
QPoint(polBoundingRect.x() + 2, polBoundingRect.y() - 3))
elif polBoundingRect.x() - 3 > textRect.width():
# left, top aligned
boundingRect.moveTopRight(
QPoint(polBoundingRect.x() - 3, polBoundingRect.y()))
textRect.moveTopRight(
QPoint(polBoundingRect.x() - 5, polBoundingRect.y()))
elif (polBoundingRect.bottom() + 3 + textRect.height() <
self.rect().bottom()) and \
polBoundingRect.right() > textRect.width():
# at bottom, right aligned
boundingRect.moveTopRight(
QPoint(polBoundingRect.right(), polBoundingRect.bottom() + 3))
#.........这里部分代码省略.........