title: How to automatically increase/decrease text size in label in Qt
body: <p>I have a Qt application where I have a textedit and a label. When a user presses the button, the textedit text should be displayed on label. For the label I have set few properties like word wrap is enabled and horizontal and vertically it is aligned center. Below is the screenshot :</p>
  
  <p><a href="https://i.stack.imgur.com/b0RtP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/b0RtP.png" alt="enter image description here"></a></p>
  
  <p>Now I have to automatically adjust the size of the text in label so that if someone enters a large string, then it should fit inside the label, that means size of text should decrease. And if the text string is small, then size should increase automatically to fill up the complete label. Currently if I am typing it the large string, it looks like something:</p>
  
  <p><a href="https://i.stack.imgur.com/hsqM5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hsqM5.png" alt="enter image description here"></a></p>
  
  <p>As you can see, in the above image, text is moving out of the label. It should remain inside the label. </p>
  
  <p>How to detect in application if the text is moving out of the label height &amp; width. Then how to reduce the text size. I want the size to automatically increase if the string is small and decrease it string is large to fill up the complete label. Is there any class or something provided in QT. Any help or example please. Thanks.</p>
  
  <p>EDIT: With the below code I am able to reduce the size of text to fit inside the label width but not able to make the text multi line.</p>
  
  <pre><code>QString string = ui-&gt;textEdit-&gt;toPlainText();   //Getting data from textEdit
  
  ui-&gt;label-&gt;setAlignment(Qt::AlignCenter);   //Aligning label text to center
  QFont f("Arial",50);        //Setting the default font size to 50
  QFontMetrics fm(f);
  ui-&gt;label-&gt;setFont(f);      //Setting the font to the label
  int width = fm.width(string);   //Getting the width of the string
  int size;
  while(width &gt;= 870)     //870 is the max width of label
  {
  
      size = ui-&gt;label-&gt;font().pointSize()-1;     //Reduce font size by 1
      QFont newFont("Arial",size);            
      QFontMetrics nfm(newFont);          
      ui-&gt;label-&gt;setFont(newFont);        //Set the new font with new size
      width = nfm.width(string);      //Get the new width
  }
  ui-&gt;label-&gt;setText(string);
  </code></pre>