Qt 5.10 Book Examples
GrabWidget.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // GrabWidget.cpp
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #include <QtWidgets>
12 #include "GrabWidget.h"
13 
14 // ----------------------------------------------------------------------
15 GrabWidget::GrabWidget(QWidget* pwgt /*=0*/) : QWidget(pwgt)
16 {
17  resize(640, 480);
18 
19  m_plbl = new QLabel();
20 
21  QPushButton* pcmd = new QPushButton("Capture Screen");
22  connect(pcmd, SIGNAL(clicked()), SLOT(slotGrabScreen()));
23 
24  //Layout setup
25  QVBoxLayout* pvbxLayout = new QVBoxLayout;
26  pvbxLayout->addWidget(pcmd);
27  pvbxLayout->addWidget(m_plbl);
28  setLayout(pvbxLayout);
29 }
30 
31 // ----------------------------------------------------------------------
33 {
34  QDesktopWidget* pwgt = QApplication::desktop();
35  QPixmap pic = QPixmap::grabWindow(pwgt->screen()->winId());
36 
37  m_plbl->setPixmap(pic.scaled(m_plbl->size()));
38 }
void slotGrabScreen()
Definition: GrabWidget.cpp:32
GrabWidget(QWidget *pwgt=0)
Definition: GrabWidget.cpp:15