質問

First of all, I'm sorry because I don't have any code examples to provide (it's quite complex to narrow it down).

Essentially, I have QLabel and I'd like to access the height of the label after the word wrap has been applied.

It seems that it always return me the default value (640x480) instead of the actually height it needs (427 pixels).

It's weird because, without .setWordWrap, I get the correct value (16449 x 13).

Any ideas?

役に立ちましたか?

解決

Just inherit a custom class from QLabel and reimplement the function "resizeEvent"

class NewLabel(QLabel):
    def __init__(self, text):
        super(NewLabel, self).__init__(text)

    def resizeEvent(self, event):
        width = self.width()
        height = self.height()

        # you can then emit a signal with the size information
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top