Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, June 2007
Press Alt-PrintScreen for a MDI child snapshot?


Message 1 in thread

H All,

For a focused top widget window, press Alt-PrintScreen gives a snapshot 
of the window itself. But this does not apply for a MDI child, where 
Alt-PrintScreen always gives the whole MDI, not its child’s snapshot. 
Then, I have to use a software to cut off, boring:(

Is there a way to get precise snapshot of a MDI child?

(I'm in WindowsXP, and the MDI can be QWorkspace/QMdiArea in a QMainWindow)

Thanks,
Lingfa


--
 [ signature omitted ] 

Message 2 in thread

Hi Lingfa,

> Is there a way to get precise snapshot of a MDI child?

Yes it is. QWidget::render -- the swiss army render tool -- is very 
handy in this case.

Something like this should do the trick:

...
QPixmap pixmap(subWindow->size());
subWindow->render(&pixmap);
pixmap.save("snapshot.png");
...


-- 
 [ signature omitted ] 

Message 3 in thread

> Yes it is. QWidget::render -- the swiss army render tool -- is very 
> handy in this case.
>
> Something like this should do the trick:
>
> ...
> QPixmap pixmap(subWindow->size());
> subWindow->render(&pixmap);
> pixmap.save("snapshot.png");
> ...
>
Bjoern Erik Nilsen,

Great! I get it. I put a slot to receive the trigger signal, and save 
the snapshot as you suggested.

void MainWindow::snapshot()
{
    QWidget *child = workspace->activeWindow();
    if(!child) return;
    QPixmap pixmap(child->size());
    child->render(&pixmap);
    pixmap.save("snapshot.png");
}

Very helpful! Thanks,
Lingfa





--
 [ signature omitted ] 

Message 4 in thread

This mostly works. If your object is derived from QWidget, it works great.
However, if it is derived from QFrame (one example) the right and bottom
edges get clipped, and the image is offset by the frame edge. I am still
experimenting with how to get the QFrame part to render completely within
the QPixmap.

Keith
**Please do not reply to me, reply to the list.**

On 06-26-2007 11:03 AM, "Bjoern Erik Nilsen" wrote:

> Hi Lingfa,
> 
>> Is there a way to get precise snapshot of a MDI child?
> 
> Yes it is. QWidget::render -- the swiss army render tool -- is very
> handy in this case.
> 
> Something like this should do the trick:
> 
> ...
> QPixmap pixmap(subWindow->size());
> subWindow->render(&pixmap);
> pixmap.save("snapshot.png");
> ...
> 


--
 [ signature omitted ] 

Message 5 in thread

Keith Esau wrote:

>This mostly works. If your object is derived from QWidget, it works great.
>However, if it is derived from QFrame (one example) the right and bottom
>edges get clipped, and the image is offset by the frame edge. 
>
Hi Keith Esau,

As I checked QFrame as a MDI child, there is no such a drawback as you 
mentioned.

But I do find it does not work with QGLWidget at all. It gives a gray 
empty rectangle.
 
Lingfa



--
 [ signature omitted ]