PDA

View Full Version : geting QLabel text ontop of other QLabel displaying image



krystosan
15th December 2013, 14:40
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.QSizePoli cy.Ignored,
QtGui.QSizePolicy.Ignored)
self.overlayExifText.setStyleSheet("QLabel { color : blue; }")
self.overlayExifText.setAlignment(QtCore.Qt.AlignT op)
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 (http://goo.gl/2oM9LH)

anda_skoa
15th December 2013, 18:35
Your container label doesn't have a layout. So its child label doesn't get resized correctly when its content changes

Cheers,
_