PDA

View Full Version : Can i save or convert qwtplot into say .jpg or .jpeg, or ....!



Krish
18th March 2008, 17:16
Hello! Friends,
I am working with Qt4.3 on WinXp. I have a application with qwtplot to draw curves of my application. Now i want to save/convert the drawn qwtplot into a.jpg or. jpeg or .bitmap or any format and save it to the same directory which i can afterwards use to analyse few things.

Can anyone please suggest me the right path to do the needful.

Thanks in Advance:)

Uwe
18th March 2008, 18:33
a) Use QwtPlot::print(QPaintDevice&, ...);
b) Use QPixmap::grabWidget

I always recommend a) because the plot is rendered to the geometry of your target and with SVG or PDF you can have a scalable vector graphics format. F.e. you can zoom in a PDF viewer later ( limited by the fact, that Qwt still uses integers, because of Qt3 compatibility ).
The bode example shows how to do it.

With b) you get a screenshot of your window.

Uwe

Krish
19th March 2008, 11:30
Hello! Uwe,
Thanks very much for informing me that. I got the required result with step a).
But i also want to save the screenshot of my widget, for which i tried step b) but not working:(
Here is what i tried: -

QPixmap screen;
screen.grabWidget(this);
screen.save("screenshot","JPG",-1);

Can you please suggest where am i going wrong?

Thanks in advance.

wysota
19th March 2008, 11:46
grabWidget() is a static method.

thadeu
12th May 2008, 17:55
Hello! Uwe,
Thanks very much for informing me that. I got the required result with step a).
But i also want to save the screenshot of my widget, for which i tried step b) but not working:(
Here is what i tried: -

QPixmap screen;
screen.grabWidget(this);
screen.save("screenshot","JPG",-1);

Can you please suggest where am i going wrong?

Thanks in advance.

I think you need to do this:
QPixmap screen;
screen = QPixmap::grabWidget(this);
screen.save("screenshot","JPG",-1);

Thadeu

Krish
20th May 2008, 13:24
Hey! Thanks Thadeu for replying, but i have already solved the problem.

Best Regards.:)

Amrita Singh
29th December 2008, 07:00
hello everyone

i had to reopen this thread i am sorry for not understanding it.I have multiple Qt windows and want to save each of them in png or bmp and not as a screenshot,but with a name.
i am using Qt 3.1 in redhat9.0 n rtlinux 3.1.
As suggested by Uwe

Qwtplot::print(QPaintdevice &paintdevice,const Qwtplotprintfilter &pfilter =Qwtplotprintfilter())
how is this done ? does it mean derive QPaintdevice object from print() and get the geometry of the window.what does Qwtplotprintfilter does.Is this function helpful for print.

how to save?.
hello krish how did u solve the problem,i am very new to qwt.

regards
Amrita

wysota
30th December 2008, 10:59
QPaintDevice is a base class for object you can "draw on", such as QWidget, QPrinter, QImage or QPixmap. Therefore what you need to do is pass a pointer to the image object you want to render the widget on and then save the image to disk.

Amrita Singh
30th December 2008, 12:06
hi

thanks wysota for writing simply.Uwe comments were also helpful. i could figure it out
Qpixmap screen;
QwtPlotPrintFilter filter;

apply options;
screen=QPixmap::grabWidget(this);
screen.fill(Qt::white);
_plot->print(screen,filter);
screen.save(filename,"PNG",-1);

this sequence got me a window saved with all scales intact.

regards
Amrita

Uwe
30th December 2008, 12:22
QPixmap screen;
screen=QPixmap::grabWidget(this);

If you want a screenshot you already have it in screen and you have to remove your following code, that overwrites your screenshot. If not the code above is pointless and you better initialize your pixmap this way:


QPixmap screen(800, 600); // or any other size you like.

Uwe

wysota
30th December 2008, 12:22
If you use grabWidget, there is no point in calling print. Do one or the other, otherwise you'll get a huge overhead. Instead of grabWidget I suggest you create a pixmap with appropriate dimensions in the first place.

QPixmap screen(this->size()); // or better yet _plot->size() if available
_plot->print(screen, filter);

giusepped
31st December 2008, 13:30
See also this thread
http://www.qtcentre.org/forum/f-qwt-23/t-saving-qwt-plot-as-image-17616.html