title: Dynamically change font size of QLabel to fit available space
body: <p>I'm trying to make an horizontal layout with 3 <code>QLabel</code> scale use all its available space. More specifically, this is what I have</p>
  
  <p><a href="https://i.stack.imgur.com/lF7Yq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lF7Yq.png" alt="Example"></a></p>
  
  <p>this is what I am aiming for</p>
  
  <p><a href="https://i.stack.imgur.com/eKH3x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eKH3x.png" alt="enter image description here"></a></p>
  
  <p>At the moment, the second image is achieved by changing the stylesheet of the qlabels with a slider. Additionally, since I have the the three labels in a layout inside a groupbox, the groupbox resizes to fit its contents, cool.</p>
  
  <p>Now I wanted to drop the slider approach and instead autofit the space available when moving the splitters. In <a href="https://stackoverflow.com/questions/8796380">this</a> question, OP reimplements the <code>resizeEvent</code>, and I've seen other posts suggesting the same, changing point by point with this <code>while( !doesFit )</code> or something similar.</p>
  
  <p>I tried using this approach, both on the resize event and on the splitterMoved event. However, this approach is way prone to feedback loops and other display errors caused. In the other question, they suggest enabling ignoreSizePolicy to prevent the size policy retriggering the sizeevent, but I like how qt handles the size of the layout, how it keeps a minimum size and then it folds the widget if the user insists. Maybe it would work if the <code>HLayout</code> would ignore the resize events triggered by the <code>QLabels</code>, still IMHO unclean thought.</p>
  
  <p>I was wondering if that's the recommended way of achieving this, and wether a less unstable solution exists, maybe using using stylesheets. There are some behaviours that I could also drop, the minimum size limit (so the user could potentially hide the groupbox).</p>
  
  <p>If that's the recommended way of doing it, how should I use the fontmetrics if I have three separate labels, one of which (the number) changes its text dynamically and rapidly? It should not have an impact on performance, and that <code>while</code> loop makes me wary.</p>
  
  <p>It doesn't sound like the <code>while(!fit)</code> approach is going to cut it. Or does it?</p>
  
  <p>--- Edit regarding the duplicate question</p>
  
  <p><a href="https://stackoverflow.com/questions/36575192/how-to-make-the-text-fill-all-the-qlabels-space">Another post</a> creates an event filter, which might also work if reworked to deal with a layout with 3 labels. I finally used a version of the first mentioned post with the variation of the post mentioned in the comments. I'll post the answer if the question is reopened.</p>