If you enable wordWrap on a QLabel, it calculates the sizeHint() incorrectly. When there is a certain length of text in the label, it seems to calculate the sizeHint() based on if the text were wrapped -- even when it isn't -- causing the height to be larger than it should. Here is a simple example:<br>
<br>####################################################<br>from PyQt4 import QtGui<br><br>class MyWidget(QtGui.QWidget): <br> def __init__(self, wordWrap, parent=None):<br> super(MyWidget, self).__init__(parent)<br>
self.setFixedWidth(800)<br> <br> self.label = QtGui.QLabel()<br> self.label.setFrameStyle(QtGui.QFrame.Box)<br> self.label.setWordWrap(wordWrap)<br> self.label.setText("Word wrap is set to '%s'" % wordWrap)<br>
<br> layout = QtGui.QVBoxLayout()<br> layout.addWidget(self.label)<br> self.setLayout(layout)<br><br>if __name__ == "__main__":<br> app = QtGui.QApplication([])<br> w1 = MyWidget(True)<br>
w2 = MyWidget(False)<br> w1.show()<br> w2.show()<br> print "wordWrap sizeHint() =", w1.label.sizeHint()<br> print "non-wordWrap sizeHint() =", w2.label.sizeHint()<br> app.exec_()<br>
####################################################<br>
<br>If you run this, you see that the label with wordWrap enabled has a larger top and bottom margin, and the sizeHint returned is 112x33 whereas the one without wordWrap has a sizeHint of 169x18.<br><br>Any ideas why this is and how to avoid it?<br>
<br>Thanks,<br>-Jugdish<br>