def paint(self, painter, rect): panel = QStyleOptionFrame() panel.initFrom(self) panel.lineWidth = 2 panel.midLineWidth = 0 panel.rect = panel.rect.adjusted(*self._margins) style = self.style() style.drawPrimitive(QStyle.PE_Frame, panel, painter, self) rect = style.subElementRect(QStyle.SE_FrameContents, panel, self) painter.fillRect(rect, Qt.white) innerRect = rect.adjusted(2, 2, -2, -2) if self._color is not None: painter.fillRect(innerRect, self._color) else: pen = painter.pen() pen.setColor(strikeColor) pen.setWidthF(1.5) painter.setPen(pen) painter.setRenderHint(QStylePainter.Antialiasing) painter.setClipRect(innerRect) bL = innerRect.bottomLeft() bL.setY(bL.y() + .5) tR = innerRect.topRight() tR.setY(tR.y() + 1) painter.drawLine(bL, tR)
def paint(self, painter, rect): panel = QStyleOptionFrame() panel.initFrom(self) panel.lineWidth = 2 panel.midLineWidth = 0 panel.rect = panel.rect.adjusted(*self._margins) panel.state = panel.state | QStyle.State_Sunken self.style().drawPrimitive(QStyle.PE_Frame, panel, painter, self) r = self.style().subElementRect(QStyle.SE_FrameContents, panel, self) painter.fillRect(r, Qt.white) painter.fillRect(r.adjusted(2, 2, -2, -2), self._color)
def sizeHint(self): fm = QFontMetrics(self.font()) # FIXME: 暂时不是太懂应该怎样正确的计算 w 和 h # 计算 h 的一个原则是让高度正好能够显示一行 h = max(fm.height() + fm.ascent() - fm.descent(), 14) w = self.width() - 4 opt = QStyleOptionFrame() opt.initFrom(self) return self.style().sizeFromContents( QStyle.CT_LineEdit, opt, QSize(w, h).expandedTo(QApplication.globalStrut()), self)
def sizeHint(self): fm = QFontMetrics(self.font()) # FIXME: 暂时不是太懂应该怎样正确的计算 w 和 h # 计算 h 的一个原则是让高度正好能够显示一行 h = max(fm.height() + fm.ascent() - fm.descent(), 14) w = self.width() - 4 opt = QStyleOptionFrame() opt.initFrom(self) return self.style().sizeFromContents( QStyle.CT_LineEdit, opt, QSize(w, h).expandedTo(QApplication.globalStrut()), self )
def paintEvent(self, event): p = QStylePainter(self) opt = QStyleOptionFrame() opt.initFrom(self) p.drawPrimitive(QStyle.PE_PanelTipLabel, opt) p.end()
def paintEvent(self, event: QPaintEvent) -> None: """ Render the custom widget """ painter = QStylePainter() painter.begin(self) x = 0 y = 0 width = self.width() rect = self.rect() # type: QRect if self.display_type == DestinationDisplayType.usage_only and QSplitter( ).lineWidth(): # Draw a frame if that's what the style requires option = QStyleOptionFrame() option.initFrom(self) painter.drawPrimitive(QStyle.PE_Frame, option) w = QSplitter().lineWidth() rect.adjust(w, w, -w, -w) palette = QPalette() backgroundColor = palette.base().color() painter.fillRect(rect, backgroundColor) if self.storage_space is None: painter.end() return highlight_menu = self.mouse_pos == DestinationDisplayMousePos.menu if self.display_type != DestinationDisplayType.usage_only: # Render the folder icon, folder name, and the menu icon self.deviceDisplay.paint_header(painter=painter, x=x, y=y, width=width, display_name=self.display_name, icon=self.icon, highlight_menu=highlight_menu) y = y + self.deviceDisplay.device_name_height if self.display_type != DestinationDisplayType.folder_only: # Render the projected storage space if self.display_type == DestinationDisplayType.usage_only: y += self.deviceDisplay.padding photos_size_to_download, videos_size_to_download = adjusted_download_size( photos_size_to_download=self.photos_size_to_download, videos_size_to_download=self.videos_size_to_download, os_stat_device=self.os_stat_device, downloading_to=self._downloading_to) details = make_body_details( bytes_total=self.storage_space.bytes_total, bytes_free=self.storage_space.bytes_free, files_to_display=self.files_to_display, marked=self.marked, photos_size_to_download=photos_size_to_download, videos_size_to_download=videos_size_to_download) self.deviceDisplay.paint_body(painter=painter, x=x, y=y, width=width, details=details) painter.end()
def paintEvent(self, *opts): painter = QStylePainter(self) option = QStyleOptionFrame() option.initFrom(self) painter.drawPrimitive(QStyle.PE_Frame, option) super().paintEvent(*opts)