Skip to content

MkWidgetScreenShot

Base classes

Name Children Inherits
MkBinaryImage
mknodes.basenodes.mkbinaryimage
Image carrying the data by itself.

⋔ Inheritance diagram

graph TD
  1473367135056["prettyqtmarkdown.MkWidgetScreenShot"]
  1473287587088["mkbinaryimage.MkBinaryImage"]
  1473287553904["mkimage.MkImage"]
  1473287579280["mknode.MkNode"]
  1473287420192["node.Node"]
  140713234304496["builtins.object"]
  1473287587088 --> 1473367135056
  1473287553904 --> 1473287587088
  1473287579280 --> 1473287553904
  1473287420192 --> 1473287579280
  140713234304496 --> 1473287420192

🛈 DocStrings

Bases: MkBinaryImage

Node to easily create and embed a widget screenshot into docs.

Source code in prettyqt\prettyqtmarkdown\mkwidgetscreenshot.py
class MkWidgetScreenShot(mknodes.MkBinaryImage):
    """Node to easily create and embed a widget screenshot into docs."""

    def __init__(
        self,
        widget: widgets.QWidget,
        caption: str = "",
        path: str | None = None,
        title: str = "Image title",
        header: str = "",
        resize_to: datatypes.SizeType | None = None,
    ):
        """Constructor.

        Arguments:
            widget: Widget to make a screenshot from
            caption: Image caption
            path: Image path
            title: Image title
            header: Section header
            resize_to: widget screenshot size
        """
        if path is None:
            path = f"{widget.__class__.__name__}_screenshot.png"
        logger.info(f"Screenshot for {widget}")
        self.widget = widget
        widget.setAttribute(constants.WidgetAttribute.WA_DontShowOnScreen)
        widget.show()
        widget.adjustSize()
        widgets.app().processEvents()
        pixmap = widget.grab()
        widget.hide()
        widget.deleteLater()
        widgets.app().processEvents()
        ba = core.ByteArray()
        buffer = core.QBuffer(ba)
        buffer.open(core.QIODeviceBase.OpenModeFlag.WriteOnly)
        pixmap.save(buffer, "PNG")
        super().__init__(
            data=ba.data(),
            path=path,
            header=header,
            caption=caption,
            title=title,
        )

__init__(widget: widgets.QWidget, caption: str = '', path: str | None = None, title: str = 'Image title', header: str = '', resize_to: datatypes.SizeType | None = None)

Constructor.

Parameters:

Name Type Description Default
widget QWidget

Widget to make a screenshot from

required
caption str

Image caption

''
path str | None

Image path

None
title str

Image title

'Image title'
header str

Section header

''
resize_to SizeType | None

widget screenshot size

None
Source code in prettyqt\prettyqtmarkdown\mkwidgetscreenshot.py
def __init__(
    self,
    widget: widgets.QWidget,
    caption: str = "",
    path: str | None = None,
    title: str = "Image title",
    header: str = "",
    resize_to: datatypes.SizeType | None = None,
):
    """Constructor.

    Arguments:
        widget: Widget to make a screenshot from
        caption: Image caption
        path: Image path
        title: Image title
        header: Section header
        resize_to: widget screenshot size
    """
    if path is None:
        path = f"{widget.__class__.__name__}_screenshot.png"
    logger.info(f"Screenshot for {widget}")
    self.widget = widget
    widget.setAttribute(constants.WidgetAttribute.WA_DontShowOnScreen)
    widget.show()
    widget.adjustSize()
    widgets.app().processEvents()
    pixmap = widget.grab()
    widget.hide()
    widget.deleteLater()
    widgets.app().processEvents()
    ba = core.ByteArray()
    buffer = core.QBuffer(ba)
    buffer.open(core.QIODeviceBase.OpenModeFlag.WriteOnly)
    pixmap.save(buffer, "PNG")
    super().__init__(
        data=ba.data(),
        path=path,
        header=header,
        caption=caption,
        title=title,
    )