fix: 回退 setWidgetResizable(False) 恢复图像显示 + 保留滚动条策略修复

setWidgetResizable(False)+QSizePolicy.Ignored 导致 QLabel
  无有效 sizeHint, 图像不显示。

回退为 setWidgetResizable(True), 保留显式 ScrollBarAsNeeded
  策略 (原默认可能为 AlwaysOff 导致滚动条异常)。
This commit is contained in:
duxin
2026-07-08 17:55:34 +08:00
parent 830589c108
commit f496b28c8c

View File

@ -978,17 +978,13 @@ class ImageViewerWidget(QWidget):
layout.addLayout(toolbar)
self.scroll_area = QScrollArea()
# setWidgetResizable(False): QLabel 保持自身 pixmap 固有尺寸,
# 放大时自然超出视口触发滚动条,而非被 QScrollArea 强制压缩
self.scroll_area.setWidgetResizable(False)
self.scroll_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.scroll_area.setWidgetResizable(True)
self.scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.scroll_area.setStyleSheet("background-color: white;")
self.image_label = QLabel()
self.image_label.setAlignment(Qt.AlignCenter)
self.image_label.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
self.image_label.setStyleSheet("background-color: white;")
self.scroll_area.setWidget(self.image_label)