开发者

qt4.7: Can't see the text of QLabel derived class

开发者 https://www.devze.com 2023-02-15 12:01 出处:网络
I derived from QLabel class. I want to redefine some events(e.g. mousePressEvent and paintEvent). But in this case the content of QLabel derived class(e.g. text) is invisible. SetEnabled and SetVisibl

I derived from QLabel class. I want to redefine some events(e.g. mousePressEvent and paintEvent). But in this case the content of QLabel derived class(e.g. text) is invisible. SetEnabled and SetVisible are not helpful. Can u tell me why client area of label is invisible?(but the reaction on events is ok).

class PaintRect : public QLabel {
public:
    explicit PaintRect(QWidget *parent = 0);
/*
private:
    voi开发者_运维知识库d paintEvent(QPaintEvent *ev);
    void mousePressEvent(QMouseEvent *ev);
*/
};

If uncomment events defenition and create object and show() them, the client area of object is invisible.


Maybe you need to call the QLabel constructor from your PaintRect constructor?

Or maybe you need to call the parent's paintEvent from the PaintRect's paintEvent.


Thanks all! I understand why the client area of label was invisible. I redefined a paintEvent with no code. There is 2 ways: call base class paint to draw text and oters or do it in redefined paintEvent.

0

精彩评论

暂无评论...
验证码 换一张
取 消