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:
class PaintWidget
: public QWidget{Q_OBJECT
public:
b=new MyPushButton("Hello world",this);
}
protected:
b->repaint();
p.drawLine(0,0,width(),height());
event->ignore();
}
MyPushButton *b;
};
class PaintWidget : public QWidget{
Q_OBJECT
public:
PaintWidget(QWidget *parent){
b=new MyPushButton("Hello world",this);
}
protected:
virtual void paintEvent(QPaintEvent *event){
b->repaint();
QPainter p(this);
p.setPen(QColor("red"));
p.drawLine(0,0,width(),height());
event->ignore();
}
MyPushButton *b;
};
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!
Bookmarks