PDA

View Full Version : ScrollArea save as image



jackajack01
20th August 2012, 21:34
Hi

I have several "curves" (as seen in the attached picture) these curves are contained in a QVBoxLayout and this in turn is contained in a QScrollArea.

my question is, is there any way to keep these "curves" as an image file? ie jpg, png, tiff, etc..

8139

StrikeByte
21st August 2012, 13:29
Yea this should be possible
try rendering the widget
QPixmap pixmap(rectangle->size()); //change size to the size of the curves
widget->render(&pixmap, QPoint(), QRegion(rectangle));

get the internal widget from the QVBoxLayout and render it

Added after 7 minutes:

I tried it and it works like a charm, i used pixmap.save(filename); to save the image

jackajack01
21st August 2012, 14:57
who is rectangle?? who is a widget???

I am putting it to you as ScrollArea widget and you have a QWidget as a rectangle that is contained in the ScrollArea and does not work

You can post the code that you worked?

StrikeByte
21st August 2012, 15:09
What type is the curve? is it inherited from QWidget?

this is the code I used:


QPixmap pixmap(pushbutton->rect().size());


pushbutton->render(&pixmap,QPoint(),QRegion(pushbutton->rect()));
pixmap.save("c:/test.png");

jackajack01
21st August 2012, 15:17
is a bit complicated ... The curves are a QGraphicsView ... as are several curves put them inside a QVBoxLayout ... And how could place the direct layout ScrollArea because not trigger the scrollbar, I had to put the layout in a Qwidget this widget and put it in the ScrollArea.

I'm doing well ... and does not work



QPixmap pixmap(scroll->rect().size());

scroll->render(&pixmap,QPoint(),QRegion(scroll->rect()));
pixmap.save("D:/test.png");

spirit
21st August 2012, 15:21
So, you need to render
...I had to put the layout in a Qwidget this widget.. as StrikeByte said.

StrikeByte
21st August 2012, 15:29
Then u need to render the QWidget that you placed inside the scrollarea

spirit
21st August 2012, 15:32
To simplify this task use QScrollArea::widget.

jackajack01
21st August 2012, 19:47
I'm sorry, I'm hard of understanding today. not referred to render the QWidget. I'm doing this and not working



scroll = new QScrollArea();
wid = new QWidget(scroll);
layout = new QHBoxLayout(wid);


QPixmap pixmap(wid->rect().size());
wid->render(&pixmap,QPoint(),QRegion(wid->rect()));
pixmap.save("D:/test.png");

StrikeByte
22nd August 2012, 07:34
If you use the code from your last post it is normal that there is no picture.
The widget doesn't have a size and there is nothing to show

try this code


scroll = new QScrollArea();
wid = new QWidget(scroll);
btn = new QPushButton("test",wid);
wid->setGeometry(0,0,200,200);
layout = new QHBoxLayout(wid);


QPixmap pixmap(wid->rect().size());
wid->render(&pixmap,QPoint(),QRegion(wid->rect()));
pixmap.save("D:/test.png");