Answer the question
In order to leave comments, you need to log in
How to wrap text on buttons in PyQt5?
Good afternoon everyone! I ran into such a problem: I have buttons, in which I want to display sentences from a different number of words (2-10), now this sentence is displayed in one line and the words are not wrapped. How to make automatic hyphenation, perhaps by space? Is it possible to automatically adjust the text size based on the amount of text? Tried to replace spaces with ]\n, but in this case it is displayed as text and doesn't wrap. I tried to use some CSS stuff, but none of them helped me, although maybe I used the wrong one. In general, how to implement it? Thank you very much in advance for your answer!
Answer the question
In order to leave comments, you need to log in
2 options
1: Add a layout to the button, to the label layout, call setWordWrap(True) on the label (just a tip from stackoverflow)
2: Draw the label on top of the button
In any case, the label
From the bad advice section.
Option number 1 do instead of button QLabel
class QLabel_alterada(QLabel):
clicked=pyqtSignal()
def __init__(self, parent=None):
QLabel.__init__(self, parent)
def mousePressEvent(self, ev):
self.clicked.emit()
Try using the first or second answer.
https://stackoverflow.com/questions/8969086/is-the...
Of course, a lot of text on a button is not a good design move. It's better to put all the text in a label next to the button.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question