title: Make QLabel width independent of text
body: <p>I need a <code>QLabel</code> whose width should not adapt to the contained text but which is resizeable by the user (or the layout to be exact). If the text is too long for the width of the <code>QLabel</code> it should simply be clipped.</p>
  
  <p>This question is somehow the reverse of
  <a href="https://stackoverflow.com/questions/20462126/how-to-make-qlabel-expand-width-geometry-to-accommodate-text">How to make QLabel expand width geometry to accommodate text</a>. However, the content of that question didn't help me. Neither did <a href="https://stackoverflow.com/questions/19293507/setting-text-on-a-qlabel-in-a-layout-doesnt-resize">Setting text on a QLabel in a layout, doesn&#39;t resize</a>.</p>
  
  <h1>Background</h1>
  
  <p>The <code>QLabel</code> will display identifiers (single words) coming from another system. Sometimes those identifiers change many times a second, which makes the whole layout flickering. The <code>QLabel</code> is part of a vertical dock so the width of the dock flickers.</p>
  
  <p>On the other hand, it should be up to the user to decide how much of the identifiers s/he could see. So I want to allow the user to change the width of the dock such that the width of the <code>QLabel</code> adapts to that.</p>
  
  <h1>Solution attempts</h1>
  
  <p>To achieve this I set the horizontal size policy to <code>QSizePolicy::Preferred</code> and derived my own label class from <code>QLabel</code> in which I've overridden <code>sizeHint()</code> to return a fixed size. But that didn't change the behavior.</p>
  
  <p>I know I could apply <code>QFontMetrics</code> to compute the width of the text and then cut it off to fit into the <code>QLabel</code> width. But that seems not to be the right solution, particularly as I would like to have the last letter itself clipped if it does not fit in entirely to give the user the clue that the identifier is too long to be displayed.</p>
  
  <h1>Versions</h1>
  
  <ul>
  <li>Qt 5.5.1</li>
  <li>GCC 5.4.0</li>
  <li>All from current Ubuntu 16.04 repository</li>
  </ul>