tintumahesh
tintumahesh

Reputation: 41

QPushButton text fit to button in Qt

I am trying to make a QPushbutton that will increase in size to fit the text platform independently. The text can be very long and I need the button to size itself so that all the text can be visible.

For example: I have a button with text "Restore defaults" , it is visible in win 7 . When i run this in mac os , only a part of the text ("tore defaults") is displayed. Could anyone tell me how to solve this problem, to make all the text appear on the button.

Upvotes: 4

Views: 11217

Answers (1)

laurent
laurent

Reputation: 90736

QPushButton should already do that by default. Check your form in Qt Creator and see if "Maximum Size" is set to something other than the default. If so, set both width and height to 16777215 (or click on the small red arrow next to the property).

If you are manually setting the size in code, you can use the sizeHint property to get the right dimensions:

button->resize(button->sizeHint().width(), button->sizeHint().height());

Upvotes: 4

Related Questions