title: QComboBox elided text on selected item
body: <p>So, I have a <em>QComboBox</em>. </p>
  
  <p><a href="https://i.stack.imgur.com/766AJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/766AJ.png" alt="enter image description here"></a></p>
  
  <p>If the <em>currentText()</em> is too long for the widget then I want to show an ellipsis. </p>
  
  <p>Like this :</p>
  
  <p><a href="https://i.stack.imgur.com/bbUVG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bbUVG.png" alt="enter image description here"></a></p>
  
  <p>So :</p>
  
  <pre><code>void MyComboBox::paintEvent(QPaintEvent * )
  {
        QStylePainter painter(this);
        QStyleOptionComboBox opt;
        initStyleOption(&amp;opt);
        painter.drawComplexControl(QStyle::CC_ComboBox, opt);
  
        QRect rect = this-&gt;rect();
        //this is not ideal
        rect.setLeft(rect.left() + 7);
        rect.setRight(rect.width() - 15);
        //
  
        QTextOption option;
        option.setAlignment(Qt::AlignVCenter);
  
        QFontMetrics fontMetric(painter.font());
        const QString elidedText = QAbstractItemDelegate::elidedText(fontMetric, rect.width(), Qt::ElideRight, this-&gt;currentText());
        painter.drawText( rect, elidedText, option);
  }
  </code></pre>
  
  <p>This is working flawlessy. 
  The problem is the code in between the comments, because I am hardcoding the distances from the left and right border. It makes me cringe. </p>
  
  <p>The result without that code is:</p>
  
  <p><a href="https://i.stack.imgur.com/wx1fQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wx1fQ.png" alt="enter image description here"></a></p>
  
  <p>Does anybody know a more general way to do this, without hardcoding? 
  Thank you</p>