.setToolTip是否可以使用此代码作为示例将图像添加到弹出窗口。那些。将鼠标悬停在图像上时,它会以更大的比例显示在弹出窗口中
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Ex(QWidget):
def __init__(self):
super().__init__()
self.pixmap = QPixmap()
self.image_label = QLabel()
self.image_label.setScaledContents(True)
self.button = QPushButton('открыть изображение')
self.button.clicked.connect(self.open_image)
layout = QVBoxLayout()
layout.addWidget(self.image_label)
layout.addWidget(self.button)
self.setLayout(layout)
self.open_image()
def open_image(self):
file_name = QFileDialog.getOpenFileName(self, 'Open file', '//home', "Images (*.png *.xpm *.jpg *.gif)")[0]
if file_name:
file = open(file_name, "rb")
with file:
self.img_data = file.read()
self.pixmap.loadFromData(self.img_data)
self.image_label.setPixmap(self.pixmap)
self.image_label.setFixedSize(100, 50)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Ex()
main.show()
sys.exit(app.exec_())

Qt 中的弹出式工具提示支持处理 HTML 标签。
img因此,可以通过在工具提示本身的文本中插入标签来将图像添加到工具提示中。