The answer in the post How to show tooltip image when hover on button pyqt5 shows that one can display a saved image on QToolTip. Is there way to achieve an equivalent result on an image represented by an numpy nd array without saving?
More precisely, if panda.jpg is a saved image right under C drive, then the following code modifed from the above reference link runs:
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
pybutton = QPushButton('Display Image via Tool Tip', self)
pybutton.setToolTip(r'<img src="C:\panda.jpg">')
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )
The code gives:
Consider now instead:
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import numpy as np
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
pybutton = QPushButton('Display Image via Tool Tip', self)
imarray = np.random.rand(1000,1000,3) * 255
#pybutton.setToolTip(imarray) #This line is not working
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )
Is there a way to attain an equivalent result without any saving? Converting to QImage does not seem to help.
This question is motivated because:
I have lots of array to display via a lot of tooltips and none of them will be used at all after they are displayed on the tooltip.
I have one tooltip where I want to display a video, which I will be able to do as soon as I know how to display one image using arrays without any saving because all I will need then is the
QTimeand update of the array.

setToolTipaccepts a printable text, while the contents of a numpy array is clearly not any of that. Qt is able to understand if a string is (possibly) a "rich text" (aka: HTML), but that only works for proper ascii/utf data, which is not the case of a memory dump such as a numpy container.