0

I'm trying to subclass QToolButton to elide its text. To tell how much room is left for text, I have to take button width (available) and subtract from it:

  1. icon size (available),

  2. size of the button frame with shadows and other cute effects (can't find it),

  3. padding (can't find it either).

Obviously these things are style-dependent and there must be API calls to retrieve them, but QStyle does not seem to offer anything relevant. Any suggestions?

sigil
  • 815
  • 8
  • 16
  • I looked at the documentation. It looks like this is relevant: (http://doc.qt.io/qt-4.8/application-windows.html#window-geometry) But it says " For all child widgets, the frame geometry is equal to the widget's client geometry." which seems ungood. – Cheers and hth. - Alf Mar 05 '17 at 14:47
  • @Cheers and hth. - Alf Can't see how this applies, sorry. I got a reasonably crazy two-pass idea in the meantime: create a button with text of known screen width, then subtract this known width from the resulting button width and assume it's the 'everything else' width. Meh. – sigil Mar 05 '17 at 15:03
  • We can just set the required size. I do `pBn->setIcon(icn); pBn->setIconSize(icsz); pBn->setContnentMargins(1,1,1,1);` and then use `QFontMetrics` for evaluating text size which is not precise for its `boundingRect()` and I try to use own formula with it. After all sizes calculated and summed up `pBn->setFixedSize(bnWidth, bnHeight);`. Of course I cannot offer that as an answer yet because your question is how to get the size remaining for the text. – Alexander V Mar 05 '17 at 16:57

0 Answers0