如何使得窗口widgets.at(i),不可改变其显示的图片
时间: 2024-02-17 22:05:16 浏览: 81
要使窗口的 `widgets.at(i)` 不可改变其显示的图片,可以使用Qt中的 `QLabel` 控件,并设置其 `pixmap` 属性为想要显示的图片。然后,将 `QLabel` 的 `scaledContents` 属性设置为 `True`,这样可以自动缩放图片以适应控件大小。最后,将 `QLabel` 的 `setFixedSize` 方法设置为图片的大小,这样就可以禁止用户更改控件的大小和显示的图片了。示例代码如下:
```python
from PyQt5.QtWidgets import QLabel
label = QLabel()
pixmap = QPixmap('image.png')
label.setPixmap(pixmap.scaled(label.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))
label.setScaledContents(True)
label.setFixedSize(pixmap.size())
```
阅读全文
相关推荐









