Skip to content

When the image is changed, the widget is not redrawn #4

@rhuygen

Description

@rhuygen

I created a simple class that extends from ImageViewer and when I update this loading a new Image, the widget is not redrawn.

class ImageWidget(ImageViewer):

    def __init__(self, image: Image.Image | None, id=None):
        if image is None:
            image = Image.new('L', (2295, 4540), 0)
        super().__init__(image)
        self.id = id

    def update(self, image: Image.Image):
        self.image = ImageView(image)
        self.refresh()

The solution that I found is to set the container coordinates and use on_show() instead of refresh():

class ImageWidget(ImageViewer):

    def __init__(self, image: Image.Image | None, id=None):
        if image is None:
            image = Image.new('L', (2295, 4540), 0)
        super().__init__(image)
        self.id = id

    def update(self, image: Image.Image):
        self.image = ImageView(image)
        self.image.set_container_size(*self.container_size)
        self.on_show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions