Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QPushButton text fit to button in Qt

Tags:

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.

like image 1000
tintumahesh Avatar asked Oct 20 '25 07:10

tintumahesh


1 Answers

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());
like image 157
laurent Avatar answered Oct 23 '25 06:10

laurent