From 41914453d38d01b9b69e16ccee69444d1a304bf7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 9 Feb 2012 13:46:28 +0100 Subject: Introduce QScreen::grabWindow(), deprecate QPixmap::grabWindow(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WId can be local to a screen. Change-Id: I09ca71313836a34dbf33289b254c80207a956bb1 Reviewed-by: Samuel Rødal --- src/gui/kernel/qscreen.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/gui/kernel/qscreen.cpp') diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 67eb991b19..da0716b7d5 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -41,6 +41,7 @@ #include "qscreen.h" #include "qscreen_p.h" +#include "qpixmap.h" #include "qplatformscreen_qpa.h" #include @@ -542,4 +543,51 @@ void QScreenPrivate::updatePrimaryOrientation() primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation; } +/*! + Creates and returns a pixmap constructed by grabbing the contents + of the given \a window restricted by QRect(\a x, \a y, \a width, + \a height). + + The arguments (\a{x}, \a{y}) specify the offset in the window, + whereas (\a{width}, \a{height}) specify the area to be copied. If + \a width is negative, the function copies everything to the right + border of the window. If \a height is negative, the function + copies everything to the bottom of the window. + + The window system identifier (\c WId) can be retrieved using the + QWidget::winId() function. The rationale for using a window + identifier and not a QWidget, is to enable grabbing of windows + that are not part of the application, window system frames, and so + on. + + The grabWindow() function grabs pixels from the screen, not from + the window, i.e. if there is another window partially or entirely + over the one you grab, you get pixels from the overlying window, + too. The mouse cursor is generally not grabbed. + + Note on X11 that if the given \a window doesn't have the same depth + as the root window, and another window partially or entirely + obscures the one you grab, you will \e not get pixels from the + overlying window. The contents of the obscured areas in the + pixmap will be undefined and uninitialized. + + On Windows Vista and above grabbing a layered window, which is + created by setting the Qt::WA_TranslucentBackground attribute, will + not work. Instead grabbing the desktop widget should work. + + \warning In general, grabbing an area outside the screen is not + safe. This depends on the underlying window system. + \since 5.0 +*/ + +QPixmap QScreen::grabWindow(WId window, int x, int y, int w, int h) const +{ + const QPlatformScreen *platformScreen = handle(); + if (!platformScreen) { + qWarning("%s invoked with handle==0", Q_FUNC_INFO); + return QPixmap(); + } + return platformScreen->grabWindow(window, x, y, w, h); +} + QT_END_NAMESPACE -- cgit v1.2.3