I have a composite widget that consists of several QLabels arranged inside QBoxLayouts. When the widget is resized I want the label text to scale to fill the label area and I have implemented resizing of the text in the resizeEvent.

This works but there seems to be some sort of feedback loop happening. The composite widget is placed in a main window inside a QBoxLayout along with some other widgets. When the main window is made smaller, the composite widget initially maintains its size and then resizes toward the correct size in several (about 10-15) steps. If the the text height is set to more than about 0.8 times the label height then on resizing the text grows larger with each step until eventually the app crashes.

Is this the correct approach to achieve this effect? If so, what might the problem be with the resizing?

Below is the resizeEvent code.

Qt Code:
  1. def resizeEvent(self, evt):
  2. print("resizeEvent", evt.size().width(), evt.size().height())
  3. QFrame.resizeEvent(self, evt)
  4.  
  5. dataLabels = self.dataPanels.values()
  6.  
  7. for label in dataLabels:
  8. font = label.font()
  9. h = label.height()
  10. h2 = h * 0.8
  11. font.setPixelSize(h2)
  12. label.setFont(font)
To copy to clipboard, switch view to plain text mode 

(using PyQt4 4.8, Qt 4.7.4, Win 7 & OSX 10.6)