Its simple thing, but I can't figure out why the overlay text is not displayed ontop of another QLabel,
here is the code I have that sets the overlay label that has text onto another existing label displaying image
def _buildUi(self):
self.label = QtGui.QLabel()
self.overlayExifText = QtGui.QLabel(self.label)
self.overlayExifText.setSizePolicy(QtGui.QSizePolicy.Ignored,
QtGui.QSizePolicy.Ignored)
self.overlayExifText.setStyleSheet("QLabel { color : blue; }")
self.overlayExifText.setAlignment(QtCore.Qt.AlignTop)
self.label.setBackgroundRole(QtGui.QPalette.Base)
self.label.setSizePolicy(QtGui.QSizePolicy.Ignored,
QtGui.QSizePolicy.Ignored)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.setCentralWidget(self.label)
here is the method that updates the text for current image
def showImageByPath(self, path):
if path:
self.overlayExifText.setText("\n".join(list(utils.getExifData((path)))))
image = QtGui.QImage(path)
pp = QtGui.QPixmap.fromImage(image)
self.label.setPixmap(pp.scaled(
self.label.size(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
only first letter of the text gets visible. also I tried setting some default text then it displays text with black background then that area also shows the little bit more of data the is yielded by the second method above. For full code have a look at this repo
QLabel
is display widget not a container. It's not good to see theQLabel
as a parent of anotherQlabel
! – qurban