protect call to QPainter::end()