728x90

Qixmap에 grabWindow 함수를 이용하면 됩니다.

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDir>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->pbScreenCapture, SIGNAL(clicked()), this, SLOT(Slot_ScreenCapture()));
    connect(ui->pbLabelCapture,  SIGNAL(clicked()), this, SLOT(Slot_LabelCapture()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::Slot_ScreenCapture()
{
    QPixmap qPixmap = QPixmap::grabWindow( this->winId() );
    QString sFileName = QDir::currentPath() + "/Screen" + ".PNG";

    qPixmap.save(sFileName, 0, 100);
}

void MainWindow::Slot_LabelCapture()
{
    QPixmap qPixmap = QPixmap::grabWindow( ui->label->winId() );
    QString sFileName = QDir::currentPath() + "/Label" + ".PNG";

    qPixmap.save(sFileName, 0, 100);
}

실행 화면에서 화면 전체 캡처 버튼을 누르면 좌측의 이미지가 저장되고 라벨만 캡처를 누르면 우측의 이미지가 저장됩니다.

728x90

'Programming > Qt' 카테고리의 다른 글

Qt random 값 사용  (0) 2021.02.17
Qt 데이터 시각화 도구 QCustomPlot 사용하기(1)  (2) 2021.02.17
[Qt] ProcessEvents  (0) 2020.12.22
Qt 비슷한 파일명을 가진 파일 정보 불러오기  (0) 2020.12.09
Qt QDir path static 함수  (0) 2020.12.09

+ Recent posts