方法1:
QScreen *screen = QGuiApplication::primaryScreen();
if (screen)QPixmap originalPixmap = screen->grabWindow(0);
方法2:
QDesktopWidget * pDesktoWidget = QApplication::desktop();
QScreen * pqscreen = QGuiApplication::primaryScreen() ;
QPixmap pixmap = pqscreen->grabWindow( pDesktoWidget->winId(), 0,0,500,500 );
QPainter paint1(this);
paint1.drawPixmap(0,0,pixmap.width(),pixmap.height(), pixmap );
关于:QPixmap QScreen::grabWindow(WId window, int x = 0, int y = 0, int width = -1, int height = -1);
从参数可以看出,可以获取任何ui界面的任意大小矩形范围保存到图片;
QScreen 没有public构造函数,所以需要QGuiApplication::primaryScreen() 返回QScreen指针;
方法3:
QPixmap::grabWidget
联系客服