資源簡介
Qt實現 屏幕截圖
代碼片段和文件信息
#include?“fullscreenwidget.h“
fullScreenWidget::fullScreenWidget()
{
??setWindowState(Qt::WindowActive|Qt::WindowFullScreen);
??tipWidth?=?300;?//溫馨提示框的寬度
??tipHeight?=?100;?//溫馨提示框的高度
??infoWidth?=?100;?//坐標信息框的寬度
??infoHeight?=?50;?//坐標信息框的高度
??initFullScreenWidget();
}
void?fullScreenWidget::initSelectedMenu()
{
??savePixmapAction?=?new?QAction(tr(“保存選區“)this);
??cancelAction?=?new?QAction(tr(“重選“)this);
??quitAction?=?new?QAction(tr(“退出“)this);
??contextMenu?=?new?QMenu(this);
??connect(savePixmapActionSIGNAL(triggered())thisSLOT(savePixmap()));
??connect(cancelActionSIGNAL(triggered())thisSLOT(cancelSelectedRect()));
??connect(quitActionSIGNAL(triggered())thisSLOT(hide()));
}
void?fullScreenWidget::savePixmap()
{
??QString?fileName;
??fileName?=?QFileDialog::getSaveFileName(thistr(“保存圖片“)QDir::currentPath()tr(“Images?(*.jpg?*.png?*.bmp)“));
??if(fileName.isNull())
????return;
??shotPixmap.save(fileName);
??hide();
}
void?fullScreenWidget::loadBackgroundPixmap(const?QPixmap?&bgPixmap)
{
??int?widthheight;
??width?=?QApplication::desktop()->size().width();
??height?=?QApplication::desktop()->size().height();
??loadBackgroundPixmap(bgPixmap00widthheight);
}
void?fullScreenWidget::loadBackgroundPixmap(const?QPixmap?&bgPixmap?int?x?int?y?int?width?int?height)
{
??loadPixmap?=?bgPixmap;
??screenx?=?x;
??screeny?=?y;
??screenwidth?=?width;
??screenheight?=?height;
??initFullScreenWidget();
}
QPixmap?fullScreenWidget::getFullScreenPixmap()
{
??initFullScreenWidget();
??QPixmap?result?=?QPixmap();
??result?=?QPixmap::grabWindow(QApplication::desktop()->winId());?//抓取當前屏幕的圖片
??return?result;
}
void?fullScreenWidget::paintEvent(QPaintEvent?*event)
{
??QColor?shadowColor;
??shadowColor=?QColor(000100);?//陰影顏色設置
??painter.begin(this);?//進行重繪
??painter.setPen(QPen(Qt::blue2Qt::SolidLineQt::FlatCap));//設置畫筆
??painter.drawPixmap(screenxscreenyloadPixmap);?//將背景圖片畫到窗體上
??painter.fillRect(screenxscreenyscreenwidthscreenheightshadowColor);?//畫影罩效果
??switch(currentShotState){
????case?initShot:
??????drawTipsText();
??????break;
????case?beginShot:
????case?finishShot:
??????selectedRect?=?getRect(beginPointendPoint);?//獲取選區
??????drawSelectedPixmap();
??????break;
????case?beginMoveShot:
????case?finishMoveShot:
??????selectedRect?=?getMoveAllSelectedRect();?//獲取選區
??????drawSelectedPixmap();
??????break;
????case?beginControl:
????case?finishControl:
??????selectedRect?=?getMoveControlSelectedRect();
??????drawSelectedPixmap();
??????break;
????default:
??????break;
??}
??drawXYWHInfo();?//打印坐標信息
??painter.end();??//重繪結束
??if(currentShotState?==?finishMoveShot?||?currentShotState?==?finishControl){
????updateBeginEndPointValue(selectedRect);?//當移動完選區后,更新beginPointendPoint;為下一次移動做準備工作
??}
}
void?fullScreenWidget::keyPressEvent(QKeyEvent?*event)
{
??if(event->key()?==?Qt::Key_Escape){
????initFullScreenWidget();
????hide();
??}
}
void?fullScreenWidget::mousePressEvent(QMouseEvent?*event)
{
??//當開始進行拖動進行選擇區域時
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-10-18?23:40??screenShot\
?????文件????????1093??2020-10-11?15:41??screenShot\.qmake.stash
?????文件???????34721??2020-10-11?15:41??screenShot\Makefile
?????文件??????142174??2020-10-11?15:41??screenShot\Makefile.Debug
?????文件??????142302??2020-10-11?15:41??screenShot\Makefile.Release
?????文件???????14426??2020-10-18?23:36??screenShot\cncT.pro.user
?????文件???????26550??2020-10-11?15:39??screenShot\cncT.pro.user.12
?????文件???????22603??2020-10-11?15:40??screenShot\cncT.pro.user.d76827c
?????目錄???????????0??2020-10-18?23:36??screenShot\debug\
?????文件?????3710092??2020-10-18?23:36??screenShot\debug\cncT.exe
?????文件??????992131??2020-10-11?15:41??screenShot\debug\fullscreenwidget.o
?????文件??????749117??2020-10-18?23:36??screenShot\debug\main.o
?????文件????????5695??2020-10-11?15:41??screenShot\debug\moc_fullscreenwidget.cpp
?????文件??????878874??2020-10-11?15:41??screenShot\debug\moc_fullscreenwidget.o
?????文件???????14934??2020-10-11?15:41??screenShot\debug\moc_predefs.h
?????文件????????3949??2020-10-18?23:36??screenShot\debug\moc_widget.cpp
?????文件??????683922??2020-10-18?23:36??screenShot\debug\moc_widget.o
?????文件??????787720??2020-10-18?23:36??screenShot\debug\widget.o
?????文件???????16364??2020-10-11?15:30??screenShot\fullscreenwidget.cpp
?????文件????????3813??2020-10-11?15:04??screenShot\fullscreenwidget.h
?????文件?????????168??2020-10-11?10:04??screenShot\main.cpp
?????文件?????????824??2020-10-12?02:24??screenShot\widget.h
?????文件?????????397??2020-10-11?14:37??screenShot\screenShot.pro
?????文件???????22700??2020-10-18?23:40??screenShot\screenShot.pro.user
?????文件????????1506??2020-10-18?23:36??screenShot\ui_widget.h
?????文件????????2139??2020-10-16?01:47??screenShot\widget.cpp
?????文件?????????701??2020-10-18?23:36??screenShot\widget.ui
?????目錄???????????0??2020-10-18?23:40??screenShot\release\
- 上一篇:qt cmd實現ping
- 下一篇:Qt 實現心電圖
評論
共有 條評論