Yes you can, use the drawPixmap function from your QWidget in your paint event function when you know that the pixmap is ready to be displayed.
(this technique is also known as local double-buffering)
Best of luck.
Jean
Added after 14 minutes:
I thought I'd leave you a bit more code....
Here:
void your_customwidget::update_my_pixmap ( int cx, int cy )
{
// this is an example ...
const QPalette& pal = QBASECLASSOF_YOUR_WIDGET_MAYBE::palette();
m_pixmap
= QPixmap(w, h
);
// member variable m_pixmap.fill(pal.window().color());
painter.initFrom(this);
... draw on painter here ....
}
// call this as pure virtual function from your base class in its PaintEvent...
void your_customwidget
::draw_my_contents ( QPainter *pPainter,
const QRect
& rect
) {
pPainter->drawPixmap(rect, m_pixmap, rect);
}
// now on the base:
void your_custom_base
::paintEvent ( QPaintEvent *pPaintEvent
) {
QPainter painter
(QBASECLASSOF_YOUR_WIDGET_MAYBE....
::viewport());
draw_my_contents(&painter, pPaintEvent->rect());
}
// in your_custom_base header file
...
protected:
virtual void draw_my_contents
(QPainter *pPainter,
const QRect
& rect
) = 0;
...
void your_customwidget::update_my_pixmap ( int cx, int cy )
{
// this is an example ...
const QPalette& pal = QBASECLASSOF_YOUR_WIDGET_MAYBE::palette();
m_pixmap = QPixmap(w, h); // member variable
m_pixmap.fill(pal.window().color());
QPainter painter(&m_pixmap);
painter.initFrom(this);
... draw on painter here ....
}
// call this as pure virtual function from your base class in its PaintEvent...
void your_customwidget::draw_my_contents ( QPainter *pPainter, const QRect& rect )
{
pPainter->drawPixmap(rect, m_pixmap, rect);
}
// now on the base:
void your_custom_base::paintEvent ( QPaintEvent *pPaintEvent )
{
QPainter painter(QBASECLASSOF_YOUR_WIDGET_MAYBE....::viewport());
draw_my_contents(&painter, pPaintEvent->rect());
}
// in your_custom_base header file
...
protected:
virtual void draw_my_contents(QPainter *pPainter, const QRect& rect) = 0;
...
To copy to clipboard, switch view to plain text mode
That's all,
Best of luck
Jean
Bookmarks