简体   繁体   中英

Why won't my Enaml ImageView scale down?

Here is a simple Enaml file to display a single image - an 800x1210 pixel image .

from enaml.widgets.api import Window, Container, ImageView
from enaml.image import Image

enamldef ImageViewResizeWindow(Window):
    Container:
        ImageView:
            image << Image(data=open("Mona_Lisa.jpg", "rb").read())
            scale_to_fit = True
            allow_upscaling = False
            preserve_aspect_ratio = True

The windows opens up rather large to fit the whole image in, but when I try to resize the window, it won't shrink - the image can't be downscaled, even though scale_to_fit is True. On the other hand, it will allow the window to be resized larger, but (correctly) won't upscale the image - it just adds more space around it.

Experimenting, I set allow_upscaling to True, and it allowed the image to grow, but not to shrink. It knows how to scale, but won't downscale.

Okay, maybe the ImageView must have a minimum size, so I added:

            minimum_size = (100, 100)

That should override the "intelligent minimum size" that was calculated for the ImageView widget, but makes no difference.

I am new to Enaml, so I suspect a basic level misunderstanding.

What do I need to do to get an ImageView to allow the downscaling of a large image, when the surrounding window is resized?

Versions:

  • Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
  • enaml==0.10.2
  • PyQt5==5.10.1

Setting resist_width and resist_height to 'weak' is the correct answer. You can set other constraints on the widget to give it a preferred size:

ImageView: 
    resist_width = 'weak'
    resist_height = 'weak'
    constraints = [(width == 640) | 'weak', (height == 480) | 'weak']

If I add

        resist_width = 'weak'
        resist_height = 'weak'

it will allow me to downscale.

However, it will also open at a smaller size by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM