The code below should elide the text in a label if it is longer
than it's width, and show it with ellipses (...) but it doesn't
work -- the line `msg = fm.elidedText(...' returns an empty
QString.

Any ideas why?

# begin code

from PyQt4 import QtGui, QtCore
import sys

app = QtGui.QApplication(sys.argv)

class ElidingLabel(QtGui.QLabel):
    def __init__(self, text="", parent=None):
        super(ElidingLabel, self).__init__(text, parent)
        self.msg = text

    def resizeEvent(self, event):
        width = event.size().width()
        fm = self.fontMetrics()
        msg = fm.elidedText(self.msg, width,
                            QtCore.Qt.ElideRight)
        print repr(self.msg), repr(msg), width
        self.setText(msg)

label = ElidingLabel("Lorem ipsum dolor sit amet,"
                     " consectetur cras amet.")
label.show()

sys.exit(app.exec_())

# end code

Thanks,
Roshan Mathews
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to