Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
PyQT4: QPushbutton icons and button name
SIddharthSavant last edited by SIddharthSavant
in push-button i have added a fixed size icon/image ,but when the push-button name length is longer it tends to push out the icon/image out of the push-button also the text moves out of the push-button . How fix the location of the image as well as the text because i cant change the size of the push-button,the size is fixed for push-button!
@SIddharthSavant Why is the size of the button fixed? If it has to be fixed and the text is too long then the only thing you can do is to shorten the text. You should use layouts, so the button can expand if there is enough space. See http://doc.qt.io/qt-5/layout.html and http://doc.qt.io/qt-5/examples-layouts.html
@jsulm hi, thanks for the advice .The button size fixed because ,within the mainwindow i have five more push-buttons and also screen size is 7 inch and i don't have much room to adjust the size of button. i was hoping to make image location fixed and when text reaches the maximum size of the button it should go to next line rather moving out of screen.Is there any way to do it ?
@SIddharthSavant The question is more: why do you have so long text in your button? Is it really necessary? Multiline text in a button is quite unusual and should be avoided.
It is possible to have multiple lines of text in a button, but then its hight will increase.
why do you have so long text in your button?
yes the long text is necessary ,because i dont have flexibility to reduce the length of text.
@SIddharthSavant you can insert a "new line" in your text, like:
QString text = "firstline\nsecondline";
@jsulm thanks for the help.