Phil
Phil

Reputation: 14671

How to implement setWordWrap(True) for a custom QLabel?

I'm re-implementing QLabel() by overriding its paintEvent.

What I'm doing is, to redraw the text 3 times in order to gain an emboss effect.

I'm using PyQT-PySide and the application is aimed for OS X, which does not support Qt's brilliant effects (shadow et al.). Therefore this is the solution I came up with.

Everything works fine except, implementation of setTextWrap(True). It fails.

What do I need to do to self.text() in order to wrap it accordingly to fit into the label's box?

Thank you.

Upvotes: 0

Views: 587

Answers (1)

Phil
Phil

Reputation: 14671

This is possible using the Qt.TextWordWrap flag which is then added to the drawText() method of QPainter()

Example:

    painter.drawText(self.rect(), self.alignment() | Qt.TextWordWrap, self.text())

Upvotes: 1

Related Questions