我在 QLabel 中有文本和图像,所以 setPixmap 不能满足我的要求。
据我所知,QLabel 可以通过设置 HTML label 从文件中加载图像<img src="path_to_file" />
。但是如何从内存中加载图像(例如 QImage)?由于某些图像经常使用,因此每次从文件中加载相同的图像可能会出现性能问题。
问问题
1437 次
3 回答
1
QLabel
接受QPixmaps
,可以从 构造QImage
。我不知道python接口,但也许这有帮助:
在 C++ 中,您可以像这样设置图像:
QLabel label;
QImage image("path_to_file");
QPixmap pixmap = QPixmap::fromImage(image);
label.setPixmap(pixmap);
于 2013-03-04T09:43:50.877 回答
0
您还可以将 QLabel 的样式表设置为:- QLabel{ background-image: url(/images/button.png);
于 2013-03-04T09:14:45.620 回答
0
你有两个选择:
- 使用两个标签,一个带有文本,一个带有图像。
- 使用 QPainter 在图像上绘制文本。
于 2013-03-04T06:40:11.583 回答