can not paint picture in a widget which inside a qsrcollarea
Hi All,
I want to paint pic to a widget which inside a qscroll area,
but it seems no pic paint out
here is my code :
Code:
public:
protected:
{
realPainter.
drawPixmap(0,
0,
QPixmap("./01.png"));
}
};
public:
{
w_->resize(3000,3000);
setWidget(w_);
}
protected:
{
realPainter.
drawPixmap(0,
0,
QPixmap("./01.png"));
}
private:
};
int main(int argc ,char *argv[])
{
Widget w;
w.show(); //the picture not paint out!!!
////////////////////////////
//the code blow works ,I was wondering why?:confused:
//Widget2 w;
//w.show(); //the picture not paint out!!!
/////////////////////////
app.exec();
}
Any ideas about it ?
Thanks advance for your help
Best regards,
hb
Re: can not paint picture in a widget which inside a qsrcollarea
Of course it doesn't work for your scrollarea.
I don't think you understand the paint event.
The paint event only paints when the widget gets a notification to repaint itself.
What you do is, paint another widget from the parent widget.
Although this logic might seem logical, it doesn't work.
Always paint widgets in their own paint event.
Otherwise, they might repaint themselves with the orignal paint code right after you've painted them from the parent (childs get repainted too when the parent gets repainted).
Why not add Widget2 to your scrollarea?
Re: can not paint picture in a widget which inside a qsrcollarea
Hi tbscope,
Thanks a lot for your explanation :)
Best regards,
hb