I do have a widget that is composed of some other widgets, and I want to draw something over it, how can I do that?

At first I thought that Just drawing on the paintEvent(...) should be enought, but it gets drawn under the contained widgets. Then I though about forcing to draw the children first, then my paint event... but no luck again. Basic example code looks like this:

Qt Code:
  1. class PaintWidget : public QWidget{
  2. Q_OBJECT
  3. public:
  4. PaintWidget(QWidget *parent){
  5. b=new MyPushButton("Hello world",this);
  6. }
  7.  
  8. protected:
  9. virtual void paintEvent(QPaintEvent *event){
  10. b->repaint();
  11. QPainter p(this);
  12. p.setPen(QColor("red"));
  13. p.drawLine(0,0,width(),height());
  14. event->ignore();
  15. }
  16. MyPushButton *b;
  17. };
To copy to clipboard, switch view to plain text mode 

Then I thought also to force by hand redrawing calling the paintEvent on the children first, and hiding the widget... But a "QPainter::begin: Widget painting can only begin as a result of a paintEvent" message tells me I can not do it in this way.

Anybody any idea?

(looking at the designer source code I dont get any clear idea on how to do it)

At http://www.monasteriomono.org/.../PaintWidget.tgz I put the full example.

thanks!