QPixmap QPixmap::grabWidget ( QWidget * widget, int x = 0, int y = 0, int w = -1, int h = -1 ) [static]
Creates a pixmap and paints widget in it.
If the widget has any children, then they are also painted in the appropriate positions.
If you specify x, y, w or h, only the rectangle you specify is painted. The defaults are 0, 0 (top-left corner) and -1,-1 (which means the entire widget).
(If w is negative, the function copies everything to the right border of the window. If h is negative, the function copies everything to the bottom of the window.)
If widget is 0, or if the rectangle defined by x, y, the modified w and the modified h does not overlap the widget->rect(), this function will return a null QPixmap.
This function actually asks widget to paint itself (and its children to paint themselves). QPixmap::grabWindow() grabs pixels off the screen, which is a bit faster and picks up exactly what's on-screen. This function works by calling paintEvent() with painter redirection turned on. If there are overlaying windows, grabWindow() will see them, but not this function.
If there is overlap, it returns a pixmap of the size you want, containing a rendering of widget. If the rectangle you ask for is a superset of widget, the areas outside widget are covered with the widget's background.
See also grabWindow(), QPainter::redirect() and QWidget::paintEvent().
QPixmap QPixmap::grabWindow ( WId window, int x = 0, int y = 0, int w = -1, int h = -1 ) [static]
Grabs the contents of the window window and makes a pixmap out of it. Returns the pixmap.
The arguments (x, y) specify the offset in the window, whereas (w, h) specify the width and height of the area to be copied.
If w is negative, the function copies everything to the right border of the window. If h is negative, the function copies everything to the bottom of the window.
Note that grabWindows() grabs pixels from the screen, not from the window. If there is another window partially or entirely over the one you grab, you get pixels from the overlying window, too.
Note also that the mouse cursor is generally not grabbed.
The reason we use 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.
Warning: Grabbing an area outside the screen is not safe in general. This depends on the underlying window system.
See also grabWidget().
Example: qmag/qmag.cpp.
获得pixmap后将它转换为QImage,用pixel取得一个点的颜色