[Qt-interest] MyQWidget's paintEvent will not be called if ...
James Yan
jyan972 at gmail.com
Wed Mar 11 18:35:04 CET 2009
hey all,
i write a widget public from QWidget to show a picture, so my code looks
like this:
//constructor
ImageWidget::ImageWidget(QWidget *parent,QImage* pImage) : QWidget(parent)
{
m_pImage = pImage;
setFixedSize(1,1); // MUST GIVE A SIZE, OTHERWISE PaintEvent WILL
NOT BE CALLED!
}
//paint event
void ImageWidget::paintEvent(QPaintEvent * /* event */)
{
//get the painter
QPainter painter(this);
//draw the image
if(m_pImage)
{
QImage
img(m_pImage->bits(),m_pImage->width(),m_pImage->height(),m_pImage->format());
painter.drawImage(QPoint(0,0),img);
setFixedSize(m_pImage->width(),m_pImage->height());
}
}
then, i put the widget in a scrollArea of a mainwindow, what a fun that i
found if i did not give the widget a fixed size in it's constructor, then my
picture will not be painted out, in other word, the paintEvent will alwasy
not be called! i do not know why, i think it maybe a bug or something.
thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090312/da531250/attachment.html
More information about the Qt-interest-old
mailing list