I'm using Qt 4.5.2 in WindowsXP and Qt 4.4.3 in Ubuntu 8.10 (default Intrepid repository)
My question comes from how to draw a QImage by using QGraphicsView?
(Well, yes, I did draw it by using the classical QLablel, but that seems not to be what I expected.)
Now, I manage to realize this by overloading function "drawBackground",
void CImageView
::drawBackground(QPainter *painter,
const QRectF &rect
) {
painter->drawImage(rect,*m_QTImage);
}
void CImageView::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->drawImage(rect,*m_QTImage);
}
To copy to clipboard, switch view to plain text mode
and call this drawBackGround() function in another function of the same class by
this->m_QTScene->invalidate();
drawBackground(&painter, this->m_QTScene->sceneRect());
this->m_QTScene->invalidate();
QPainter painter(this);
drawBackground(&painter, this->m_QTScene->sceneRect());
To copy to clipboard, switch view to plain text mode
where the class CImageView inherits from QGraphicsView .
However, in Ubuntu 8.10, Qt 4.4.3, I was always suggested by
"QPainter::begin: Widget painting can only begin as a result of a paintEvent."
I'm posting to ask whether it is a must to put QPainter inside the function paintEvent?
If it is a must, why this is only a warning message, but not reported as an error? Is this a difference between Qt 4.5.2 and Qt 4.4.3?
What's more, I tried to put QPainter into paintEvent by the following code
{
if(this->m_isDrawing)
{
this->m_isDrawing = false;
}
}
void CImageView::paintEvent(QPaintEvent *event)
{
if(this->m_isDrawing)
{
QGraphicsView::paintEvent(event);
this->m_isDrawing = false;
}
}
To copy to clipboard, switch view to plain text mode
and in the calling function, I use this->repaint();
But, it seems that the default "QGraphicsView:
aintEvent(event);" will help to trigger the overloaded function "drawBackground" and draw the image. But when I tried to use the above mechanism to grab images from the webcam, there is some times a white dot in the middle of captured image. Seriously no idea of why it is so. And this white dot seems only happen in Linux, but now WindowsXP.
Best Regards
JIA Pei
Bookmarks