0
votes

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

1
could you please pull the repo and see the problem ?Ciasto piekarz
@san, QLabel is display widget not a container. It's not good to see the QLabel as a parent of another Qlabel!qurban

1 Answers

1
votes

To display image and text simultaneously following approach can be useful:

  • Set the image as background image on label:

    label.setStyleSheet("background-image: url(:/1.png);")

  • Set the text you want to display on top of the image:

    label.setText("text") ..