My problem is that i didnt want to save an image locally to display it in my ui program so I converted the image to bytecode to then be stored in the code itself and display from there itself. However when I do so, It doesn't show it on the ui when I try to display it using .raise_() but displays when using .show(). I don't want to use .show() as it launches a new window to display just the image. .raise_() works when loading the image when stored locally in a directory.
What originally worked, I load the image file from the path and it displays perfectly where it should
self.label_3 = QtWidgets.QLabel(parent=self.tab)
self.label_3.setGeometry(QtCore.QRect(-80, -30, 291, 221))
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap("icon.png"))
self.label_3.setScaledContents(True)
self.label_3.setObjectName("label_3")
What I wanted to switch to so that I didnt have to save the image locally
self.base64_icon= '''
*Image converted to base64 code*
'''
self.label_3 = QLabel()
self.label_3.setPixmap(QPixmap.fromImage(QImage.fromData(base64.b64decode(self.base64_icon))))
When I use the above code and then display the label using .show(), it shows it normally in a new screen however when I use .raise_(), so that I can display it where I want as .show() just launches a new window to display the image, it doesn't display the image and that area is just blank.
Here is the link to the full code without the stylesheet and some irrelevant things removed: Link I hope it helps you help me
the way i want it to work but with .raise_()
instead of .show()
:
import sys
import base64
from PyQt6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
from PyQt6.QtGui import QPixmap, QImage
from PyQt6.QtCore import Qt
if __name__ == "__main__":
base64_image = ''' base64 encoded image '''
app = QApplication(sys.argv)
label = QLabel()
image = QImage.fromData(base64.b64decode(base64_image))
pixmap = QPixmap.fromImage(image)
label.setPixmap(pixmap)
layout = QVBoxLayout()
layout.addWidget(label)
window = QWidget()
window.setLayout(layout)
window.setWindowTitle("Image Display")
window.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint)
window.resize(pixmap.width(), pixmap.height())
window.show()
sys.exit(app.exec())