def splash_screen(): splash_n = random.randint(1, 3) path = pkg_resources.resource_filename( __name__, f"icons/orange-splash-screen-{splash_n:02}.png") pm = QPixmap(path) version = Config.ApplicationVersion if version: version_parsed = LooseVersion(version) version_comp = version_parsed.version version = ".".join(map(str, version_comp[:2])) size = 13 font = QFont("Helvetica") font.setPixelSize(size) metrics = QFontMetrics(font) br = metrics.boundingRect(version) br.moveTopLeft(QPoint(171, 438)) p = QPainter(pm) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.setFont(font) p.setPen(QColor("#000000")) p.drawText(br, Qt.AlignLeft, version) p.end() return pm, QRect(23, 24, 200, 20)
def paintEvent(self, event): painter = QPainter(self) metrics = QFontMetrics(self.font()) elided = metrics.elidedText(self.text(), Qt.ElideRight, self.width()) painter.drawText(self.rect(), self.alignment(), elided)
def splash_screen(): """ """ pm = QPixmap( pkg_resources.resource_filename(__name__, "icons/orange-splash-screen.png")) version = QCoreApplication.applicationVersion() size = 21 if len(version) < 5 else 16 font = QFont("Helvetica") font.setPixelSize(size) font.setBold(True) font.setItalic(True) font.setLetterSpacing(QFont.AbsoluteSpacing, 2) metrics = QFontMetrics(font) br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0) br.moveCenter(QPoint(436, 224)) p = QPainter(pm) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.setFont(font) p.setPen(QColor("#231F20")) p.drawText(br, Qt.AlignCenter, version) p.end() return pm, QRect(88, 193, 200, 20)
def splash_screen(): """ """ pm = QPixmap( pkg_resources.resource_filename( __name__, "icons/orange-splash-screen.png") ) version = QCoreApplication.applicationVersion() size = 21 if len(version) < 5 else 16 font = QFont("Helvetica") font.setPixelSize(size) font.setBold(True) font.setItalic(True) font.setLetterSpacing(QFont.AbsoluteSpacing, 2) metrics = QFontMetrics(font) br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0) br.moveCenter(QPoint(436, 224)) p = QPainter(pm) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.setFont(font) p.setPen(QColor("#231F20")) p.drawText(br, Qt.AlignCenter, version) p.end() return pm, QRect(88, 193, 200, 20)
def paintEvent(self, e): """ :param e: :return: """ self._is_painting = True super(EventsWidget, self).paintEvent(e) painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.setFont(QFont('Decorative', 8)) slider_pos = self._scroll.sliderPosition() start = slider_pos * self._scale end = start + self.width() * self._scale for i, track in enumerate(self._tracks): if self._break_draw: break track.draw_events(painter, start, end, track_index=i, left_shift=-self._scroll.sliderPosition(), scale=self._scale) # Draw only from pixel start to end painter.setPen(QtCore.Qt.DashLine) painter.setOpacity(0.3) # print('Draw', start, end, self._scale, self._scroll.sliderPosition(), self.width()) # Draw vertical lines for x in range(start - (start % (100 * self._scale)), end, 100 * self._scale): x2draw = (x - slider_pos * self._scale) // self._scale painter.drawLine(x2draw, 20, x2draw, self.height()) string = str(x) boundtext = painter.boundingRect(QtCore.QRectF(), string) painter.drawText(x2draw - boundtext.width() / 2, 15, string) for index, track in enumerate(self._tracks): top = self.which_top(index) # print(top) painter.drawLine(0, top, self.width(), top) painter.drawText(10, top + 15, track.title) painter.setOpacity(1.0) self._pointer.draw(painter, left_shift=-slider_pos, scale=self._scale) # Draw the time pointer painter.end() self._break_draw = False self._is_painting = False
def paintEvent(self, event): super().paintEvent(event) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setBrush(self.indicator_color) p.save() p.setPen(Qt.NoPen) fm = QFontMetrics(self.font()) width = self.rect().width() height = fm.height() + 6 rect = QRectF(0, 0, width, height) p.drawRoundedRect(rect, 5, 5) p.restore() textstart = (width - fm.width(self.indicator_text)) / 2 p.drawText(textstart, height / 2 + 5, self.indicator_text)
def paintEvent(self, e): # call the base implementation to paint normal interface super(GaugeWidgetVertical, self).paintEvent(e) draw = QPainter() draw.begin(self) window_with = self.width() - 1 diff = (self._higher - self._lower) * self.scale try: self._step = float(self.height()) / float(diff) except ZeroDivisionError: self._step = 0 y_start = self.height() - (self._minVal - self._lower) * self._step * self.scale y_end = self.height() - (self._maxVal - self._lower) * self._step * self.scale draw.setOpacity(1.0) draw.setBrush(QtCore.Qt.NoBrush) draw.setPen(QColor(200, 200, 255)) b = int(self.height() / 5) e = int(self.height() - (self.height() / 5) + 1) s = int(self.height() / 5) for i in range(b, e, s): draw.drawLine(0, i, window_with, i) draw.setBrush(QColor(33, 133, 208)) draw.setPen(QColor(33, 133, 208)) draw.setOpacity(0.7) draw.drawRect(0, y_start, window_with, y_end - y_start) draw.setFont(QFont('Decorative', 8)) draw.setPen(QColor(30, 30, 30)) draw.drawText( 3, self.height() - 3, str(self._lower) if self._use_float else str( int(round(self._lower)))) draw.drawText( 3, 10, str(self._higher) if self._use_float else str( int(round(self._higher)))) draw.drawText( 3, y_start + 11, str(self._minVal) if self._use_float else str( int(round(self._minVal)))) draw.drawText( 3, y_end - 4, str(self._maxVal) if self._use_float else str( int(round(self._maxVal)))) draw.end()
def splash_screen(): # type: () -> Tuple[QPixmap, QRect] """ Return a splash screen pixmap and an text area within it. The text area is used for displaying text messages during application startup. The default implementation returns a bland rectangle splash screen. Returns ------- t : Tuple[QPixmap, QRect] A QPixmap and a rect area within it. """ path = pkg_resources.resource_filename( __name__, "icons/orange-canvas-core-splash.svg") pm = QPixmap(path) version = QCoreApplication.applicationVersion() if version: version_parsed = LooseVersion(version) version_comp = version_parsed.version version = ".".join(map(str, version_comp[:2])) size = 21 if len(version) < 5 else 16 font = QFont() font.setPixelSize(size) font.setBold(True) font.setItalic(True) font.setLetterSpacing(QFont.AbsoluteSpacing, 2) metrics = QFontMetrics(font) br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0) br.moveBottomRight(QPoint(pm.width() - 15, pm.height() - 15)) p = QPainter(pm) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.setFont(font) p.setPen(QColor("#231F20")) p.drawText(br, Qt.AlignCenter, version) p.end() textarea = QRect(15, 15, 170, 20) return pm, textarea
def paintEvent(self, e): # call the base implementation to paint normal interface QWidget.paintEvent(self, e); draw = QPainter(); draw.begin(self) h = self.height() - 1 diff = (self._higher - self._lower) * self.scale try: self._step = float(self.width()) / float(diff) except ZeroDivisionError: self._step = 0 x_start = (self._minVal - self._lower) * self._step * self.scale x_end = (self._maxVal - self._lower) * self._step * self.scale draw.setOpacity(1.0) draw.setBrush(QtCore.Qt.NoBrush) draw.setPen(QColor(200, 200, 255)) for i in range( int(self.width()/5), int(self.width()-self.width()/5) + 1, int(self.width()/5) ): draw.drawLine(i, 0, i, h) draw.setBrush(QColor(238, 238, 238)) draw.setPen(QColor(238, 238, 238)) draw.drawRoundedRect(0, 2, self.width(), h - 4, 3, 3) draw.setBrush(QColor(33, 133, 208)) draw.setPen(QColor(33, 133, 208)) draw.drawRoundedRect(int(round(x_start)), 2, int(round(x_end - x_start)), h - 4, 3, 3) # draw.setOpacity(1.0) draw.setFont(QFont('Decorative', 8)) draw.setPen(QColor(80, 80, 80)) str(self._maxVal) if self._use_float else str(int(round(self._maxVal))) boundtext = draw.boundingRect(QtCore.QRectF(), str(self._higher) if self._use_float else str(int(round(self._higher)))) draw.drawText(self.width() - boundtext.width(), 14, str(self._higher) if self._use_float else str(int(round(self._higher)))) draw.drawText(0, 14, str(self._lower) if self._use_float else str(int(round(self._lower)))) draw.setPen(QColor(255, 255, 255)) boundtext = draw.boundingRect(QtCore.QRectF(), str(self._minVal) if self._use_float else str(int(round(self._minVal)))) draw.drawText(x_start + 2, 14, str(self._minVal) if self._use_float else str(int(round(self._minVal)))) boundtext = draw.boundingRect(QtCore.QRectF(), str(self._maxVal) if self._use_float else str(int(round(self._maxVal)))) draw.drawText(x_end - boundtext.width(), 14, str(self._maxVal) if self._use_float else str(int(round(self._maxVal)))) draw.end()
def __preview_color(self): """ Shows selected colors in two QLabel widgets. The first shows true color, while the second presents the color with an opacity as seen in the timeline and with some dummy text to preview readability. """ pixmap = QPixmap(50, 25) color = QColor(*self.color.getRgb()) # Preview color color.setAlpha(int(255 * 1.0)) pixmap.fill(color) self._ui.label_color.setPixmap(pixmap) # Preview color with transparency and some text color.setAlpha(int(255 * 0.5)) pixmap.fill(color) painter = QPainter(pixmap) painter.setFont(QFont('Decorative', 8)) painter.drawText(pixmap.rect(), QtCore.Qt.AlignCenter, "Text") painter.end() self._ui.label_color_alpha.setPixmap(pixmap)
def splash_screen(): path = pkg_resources.resource_filename(__name__, "icons/tods-splash-screen.png") pm = QPixmap(path) version = pkg_resources.get_distribution("tods").version size = 18 if len(version) < 5 else 16 font = QFont("Helvetica") font.setPixelSize(size) font.setBold(True) font.setItalic(True) font.setLetterSpacing(QFont.AbsoluteSpacing, 2) metrics = QFontMetrics(font) br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0) br.moveCenter(QPoint(440, 350)) p = QPainter(pm) p.setRenderHint(QPainter.Antialiasing) p.setRenderHint(QPainter.TextAntialiasing) p.setFont(font) p.setPen(QColor("#231F20")) p.drawText(br, Qt.AlignCenter, version) p.end() return pm, QRect(88, 193, 200, 20)
def __paintEventNoStyle(self): p = QPainter(self) opt = QStyleOptionToolButton() self.initStyleOption(opt) fm = QFontMetrics(opt.font) palette = opt.palette # highlight brush is used as the background for the icon and background # when the tab is expanded and as mouse hover color (lighter). brush_highlight = palette.highlight() if opt.state & QStyle.State_Sunken: # State 'down' pressed during a mouse press (slightly darker). background_brush = brush_darker(brush_highlight, 110) elif opt.state & QStyle.State_MouseOver: background_brush = brush_darker(brush_highlight, 95) elif opt.state & QStyle.State_On: background_brush = brush_highlight else: # The default button brush. background_brush = palette.button() rect = opt.rect icon_area_rect = QRect(rect) icon_area_rect.setRight(int(icon_area_rect.height() * 1.26)) text_rect = QRect(rect) text_rect.setLeft(icon_area_rect.right() + 10) # Background (TODO: Should the tab button have native # toolbutton shape, drawn using PE_PanelButtonTool or even # QToolBox tab shape) # Default outline pen pen = QPen(palette.color(QPalette.Mid)) p.save() p.setPen(Qt.NoPen) p.setBrush(QBrush(background_brush)) p.drawRect(rect) # Draw the background behind the icon if the background_brush # is different. if not opt.state & QStyle.State_On: p.setBrush(brush_highlight) p.drawRect(icon_area_rect) # Line between the icon and text p.setPen(pen) p.drawLine(icon_area_rect.topRight(), icon_area_rect.bottomRight()) if opt.state & QStyle.State_HasFocus: # Set the focus frame pen and draw the border pen = QPen(QColor(FOCUS_OUTLINE_COLOR)) p.setPen(pen) p.setBrush(Qt.NoBrush) # Adjust for pen rect = rect.adjusted(0, 0, -1, -1) p.drawRect(rect) else: p.setPen(pen) # Draw the top/bottom border if self.position == QStyleOptionToolBox.OnlyOneTab or \ self.position == QStyleOptionToolBox.Beginning or \ self.selected & \ QStyleOptionToolBox.PreviousIsSelected: p.drawLine(rect.topLeft(), rect.topRight()) p.drawLine(rect.bottomLeft(), rect.bottomRight()) p.restore() p.save() text = fm.elidedText(opt.text, Qt.ElideRight, text_rect.width()) p.setPen(QPen(palette.color(QPalette.ButtonText))) p.setFont(opt.font) p.drawText(text_rect, int(Qt.AlignVCenter | Qt.AlignLeft) | \ int(Qt.TextSingleLine), text) if not opt.icon.isNull(): if opt.state & QStyle.State_Enabled: mode = QIcon.Normal else: mode = QIcon.Disabled if opt.state & QStyle.State_On: state = QIcon.On else: state = QIcon.Off icon_area_rect = icon_area_rect icon_rect = QRect(QPoint(0, 0), opt.iconSize) icon_rect.moveCenter(icon_area_rect.center()) opt.icon.paint(p, icon_rect, Qt.AlignCenter, mode, state) p.restore()
def __paintEventNoStyle(self): p = QPainter(self) opt = QStyleOptionToolButton() self.initStyleOption(opt) fm = QFontMetrics(opt.font) palette = opt.palette # highlight brush is used as the background for the icon and background # when the tab is expanded and as mouse hover color (lighter). brush_highlight = palette.highlight() foregroundrole = QPalette.ButtonText if opt.state & QStyle.State_Sunken: # State 'down' pressed during a mouse press (slightly darker). background_brush = brush_darker(brush_highlight, 110) foregroundrole = QPalette.HighlightedText elif opt.state & QStyle.State_MouseOver: background_brush = brush_darker(brush_highlight, 95) foregroundrole = QPalette.HighlightedText elif opt.state & QStyle.State_On: background_brush = brush_highlight foregroundrole = QPalette.HighlightedText else: # The default button brush. background_brush = palette.button() rect = opt.rect icon_area_rect = QRect(rect) icon_area_rect.setRight(int(icon_area_rect.height() * 1.26)) text_rect = QRect(rect) text_rect.setLeft(icon_area_rect.right() + 10) # Background (TODO: Should the tab button have native # toolbutton shape, drawn using PE_PanelButtonTool or even # QToolBox tab shape) # Default outline pen pen = QPen(palette.color(QPalette.Mid)) p.save() p.setPen(Qt.NoPen) p.setBrush(QBrush(background_brush)) p.drawRect(rect) # Draw the background behind the icon if the background_brush # is different. if not opt.state & QStyle.State_On: p.setBrush(brush_highlight) p.drawRect(icon_area_rect) # Line between the icon and text p.setPen(pen) p.drawLine(icon_area_rect.topRight(), icon_area_rect.bottomRight()) if opt.state & QStyle.State_HasFocus: # Set the focus frame pen and draw the border pen = QPen(QColor(FOCUS_OUTLINE_COLOR)) p.setPen(pen) p.setBrush(Qt.NoBrush) # Adjust for pen rect = rect.adjusted(0, 0, -1, -1) p.drawRect(rect) else: p.setPen(pen) # Draw the top/bottom border if self.position == QStyleOptionToolBox.OnlyOneTab or \ self.position == QStyleOptionToolBox.Beginning or \ self.selected & \ QStyleOptionToolBox.PreviousIsSelected: p.drawLine(rect.topLeft(), rect.topRight()) p.drawLine(rect.bottomLeft(), rect.bottomRight()) p.restore() p.save() text = fm.elidedText(opt.text, Qt.ElideRight, text_rect.width()) p.setPen(QPen(palette.color(foregroundrole))) p.setFont(opt.font) p.drawText(text_rect, int(Qt.AlignVCenter | Qt.AlignLeft) | \ int(Qt.TextSingleLine), text) if not opt.icon.isNull(): if opt.state & QStyle.State_Enabled: mode = QIcon.Normal else: mode = QIcon.Disabled if opt.state & QStyle.State_On: state = QIcon.On else: state = QIcon.Off icon_area_rect = icon_area_rect icon_rect = QRect(QPoint(0, 0), opt.iconSize) icon_rect.moveCenter(icon_area_rect.center()) opt.icon.paint(p, icon_rect, Qt.AlignCenter, mode, state) p.restore()