How to implment word wrap text feature for QPushbutton ?
-
I am facing difficulty to set Translated text in QPushbutton. because other language consist long word so it get cuts in QPushbutton. Now i want to use SetWordWrap() feature of QLabel on My static QPushbutton.
Can any body suggest me best way to fix this problem ?
Is there any best way is there to deal with this situation ?
-
@Qt-embedded-developer said in How to implment word wrap text feature for QPushbutton ?:
static QPushbutton
A static push button?!
I hope you don't really have a static push button (or any other QObject based static class instance). -
Hi,
Do you mean its size does not change ?
-
Was that image a mock up? If it was not, then it seems the text is already wrapping but there is simply not enough vertical space for three lines and the widget has done the best it can.
The only way you will fit more text in a fixed box is to shrink the font. I think you could do this in an override of paintEvent(). See if the text will fit in the box using the QPainter tools. If not, shrink the font and try again. There will need to be some limits to how small you go etc.
-
@ChrisW67 no its not image mockup. its text in pushbutton. i have put "\n" character between 2 words so word come to next line.
shrinking font done the task.
But How to wrap text in Pushbutton ? can anybody give example.
-
@Qt-embedded-developer said in How to implment word wrap text feature for QPushbutton ?:
But How to wrap text in Pushbutton ? can anybody give example.
Did you try Googling for
QPushButton wrap text
? That's what I would do....It seems you have 3 options:
-
Put an explicit
\n
character into the text at the desired spot, as you say you have done. -
Create a
QLabel
and set itssetWordWrap(true)
, then super-impose it onto the center of theQPushButton
. -
Just do it with a sub-classed
QLabel
(noQPushButton
) and handle themousePressEvent
toemit
the clicked signal.
-