1
votes

I've a class that extends QWidget and contains a QLabel (lblBackground). I've overriden paintEvent function too.

I want to draw something on top of lblBackground however paintEvent method is called before the QLabel is drawn. Thus my custom drawings are overwritten.

Is there a way to change drawing order?

2

2 Answers

2
votes

Painting the children on top of their parent is the common thing to do. That being said you could try one of the following options:

  1. extend QLabel itself to paint whatever you want
  2. try to set the Qt::WA_TranslucentBackground flag on the QLabel and having an alpha channel, so that the underlying parent (QWidget) would shine through
  3. if you are only using the QLabel to paint some background, maybe you can get rid of it and paint the desired background first thing in the QWidget's paintEvent()?
1
votes

If you want to use label as a background then just create your custom widget as a child of your label. May be split some window frame related tasks if any (to be implemented as a parent of the label) and drawing/controls/etc (to be child of the label).