[Qt-interest] save widget snapshot in file
Guido Seifert
wargand at gmx.de
Thu Aug 18 23:10:31 CEST 2011
The following is a shortened snapshot of something similar I once
tried. It might give you a few ideas:
void FOO::render(void){
QImage image(this->size(),QImage::Format_RGB444);
QPainter p(&image);
image.fill(255);
this->render(&p);
QString dest = "name"+
QString::number(mImageCounter).rightJustified(4,'0')+".jpg";
image.save(dest);
++mImageCounter;
}
void FOO::paintEvent(QPaintEvent *event){
QDeclarativeView::paintEvent(event);
render();
}
I dropped this approach, because it was too straining on my ressources.
Depending on the widget the might experience 'frame drops'. But there
are several ways to optimize this code. Never did it, because this
project was dropped.
Regards.
Guido
On Thu, Aug 18, 2011 at 12:07:27PM +0400, Brilliantov Kirill Vladimirovich wrote:
> Hello!
> I have to save snapshot from widget to file.
> My function:
> void Image::make_snapshot()
> {
> QString name =
> QDateTime::currentDateTime().toString(QString("yyyyMMddhhmmsszzz.jpg"));
> QPixmap img = QPixmap::grabWidget(this);
> if (!img.save(name))
> QMessageBox::warning(this, QString("JPEG snapshot"),QString(tr("Can't
> save snapshot in file %1").arg(name)),QMessageBox::Ok);
> }
>
> This is function work with static image, but not work with dynamic.
>
> How can I solve this problem?
> Thank you and excuse me for my bad english.
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list