File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 1919class CustomGraphicsPixmapItem (QGraphicsPixmapItem ):
2020 def __init__ (self , image_path : str ):
2121 pixmap = QPixmap (image_path )
22+ if pixmap .isNull ():
23+ raise ValueError (f"Failed to load '{ image_path } '" )
2224 super ().__init__ (pixmap )
2325 self .image_filename = os .path .basename (image_path )
2426 self .setFlag (self .GraphicsItemFlag .ItemIsMovable )
@@ -90,12 +92,7 @@ def __init__(
9092 ImageKeys .scale ,
9193 )
9294 except KeyError :
93- scale_fit_image = min (
94- window_width_px / self .pixmap_item .pixmap ().width (),
95- window_height_px / self .pixmap_item .pixmap ().height (),
96- )
97- if scale_fit_image < 1.0 :
98- self .scale (scale_fit_image )
95+ self ._fit_image_to_window (window_width_px , window_height_px )
9996 else :
10097 self .scale (scale )
10198
@@ -109,6 +106,12 @@ def __init__(
109106 else :
110107 self .pixmap_item .set_position (position )
111108
109+ def _fit_image_to_window (self , window_width_px : int , window_height_px : int ):
110+ image_width = self .pixmap_item .pixmap ().width ()
111+ image_height = self .pixmap_item .pixmap ().height ()
112+ scale = min (window_width_px / image_width , window_height_px / image_height )
113+ self .scale (scale )
114+
112115 def delete (self ):
113116 self .scene .removeItem (self .pixmap_item )
114117
Original file line number Diff line number Diff line change 11from typing import Optional , Callable
22
33from PySide6 .QtCore import Qt
4- from PySide6 .QtGui import QMouseEvent
4+ from PySide6 .QtGui import QMouseEvent , QImageReader
55from PySide6 .QtWidgets import QGraphicsView , QGraphicsScene
66
77from battle_map_tv .aoe import AreaOfEffectManager
@@ -26,6 +26,8 @@ def __init__(self):
2626 self .setAlignment (Qt .AlignCenter ) # type: ignore[attr-defined]
2727 self .setHorizontalScrollBarPolicy (Qt .ScrollBarAlwaysOff ) # type: ignore[attr-defined]
2828 self .setVerticalScrollBarPolicy (Qt .ScrollBarAlwaysOff ) # type: ignore[attr-defined]
29+ # allow for large size images
30+ QImageReader .setAllocationLimit (0 )
2931
3032 scene = QGraphicsScene ()
3133 scene .setSceneRect (0 , 0 , self .size ().width (), self .size ().height ())
You can’t perform that action at this time.
0 commit comments