Reputation: 857
I have a QToolButton
with a text using toolButton->setText(....)
. However, the text is truncated when the button is rendered. I have tried increasing the width of the button using resize()
and setFixedSize
but the text is centered and still truncated. Any ideas how to make the button follow the width of the text ?
Upvotes: 1
Views: 2349
Reputation: 1
Try to set the same minimumSize(w,h)
and maximumSize(w,h)
with correct values, I mean, for example:
In Design, in the property window of your button:
width and height in geometry - 80x88, minimum and maximum must the same.
It works for me in my case. And pay attention on icon size of the button, if it is.
Upvotes: 0
Reputation: 6584
You can use QFontMetrics
to calculate the minimum size needed to display the whole text. The boundingRect
method returns a QRect
corresponding to the size of your text. You can specify flags like Qt::AlignHCenter
.
http://qt-project.org/doc/qt-5.0/qtgui/qfontmetrics.html#boundingRect-4
You can subclass QToolButton
and reimplement the setText()
method to include a call to resize()
or manage the size when you call setText()
.
Upvotes: 1