資源簡介
子類化QLabel顯示圖片并在label上畫矩形截圖并顯示,..a...d........

代碼片段和文件信息
#include?“LabelPress.h“
#include?
LabelPress::LabelPress(QWidget?*parent?/*=?0*/?):QLabel(parent)
{
}
LabelPress::LabelPress(const?QString?&text?QWidget?*parent
????Qt::WindowFlags?f):QLabel(textparentf)
{
}
void?LabelPress::init(int?id)
{
}
LabelPress::~LabelPress()
{
}
void?LabelPress::mousePressEvent(QMouseEvent?*e)
{
????if(e->button()?&&?Qt::LeftButton){
????????m_isDown?=?true;
????????m_start?=?e->pos();
????????m_stop?=?e->pos();
????}
}
void?LabelPress::mouseMoveEvent(QMouseEvent?*e)
{
????if(m_isDown){
????????m_stop?=?e->pos();
????}
????update();
}
void?LabelPress::mouseReleaseEvent(QMouseEvent?*e)
{
????if(e->button()?&&?Qt::LeftButton){
????????m_isDown?=?false;
????}
}
void?LabelPress::paintEvent(QPaintEvent?*event)
{
????QLabel::paintEvent(event);//先調用父類的paintEvent為了顯示‘背景‘!!!
????QPainter?painter(this);
????painter.setPen(QPen(Qt::red2));
????if(!m_isDown){
????????return;
????}
????painter.drawRect(QRect(m_startm_stop));
????QRect?selectedRect?=?getRect(m_start?m_stop);
????m_capturePixmap?=?m_loadPixmap.copy(selectedRect);
????signalCompleteCature(m_capturePixmap);
????if(m_capturePixmap.isNull())qDebug(“isNull“);
}
QRect?LabelPress::getRect(const?QPoint?&beginPoint?const?QPoint?&endPoint)
{
????int?x?y?width?height;
????width?=?qAbs(beginPoint.x()?-?endPoint.x());
????height?=?qAbs(beginPoint.y()?-?endPoint.y());
????x?=?beginPoint.x()?????y?=?beginPoint.y()?
????QRect?selectedRect?=?QRect(x?y?width?height);
????//?避免寬或高為零時拷貝截圖有誤;
????//?可以看QQ截圖,當選取截圖寬或高為零時默認為2;
????if?(selectedRect.width()?==?0)
????{
????????selectedRect.setWidth(1);
????}
????if?(selectedRect.height()?==?0)
????{
????????selectedRect.setHeight(1);
????}
????return?selectedRect;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-24?16:36??label\
?????目錄???????????0??2018-06-24?16:46??label\aaa\
?????文件????????1060??2018-06-24?16:35??label\aaa\aaa.pro
?????文件???????18285??2018-06-24?16:46??label\aaa\aaa.pro.user
?????文件????????2016??2018-06-24?16:35??label\aaa\labelpress.cpp
?????文件?????????865??2018-06-24?16:35??label\aaa\labelpress.h
?????文件?????????183??2018-06-24?16:35??label\aaa\main.cpp
?????文件?????????977??2018-06-24?16:35??label\aaa\mainwindow.cpp
?????文件?????????485??2018-06-24?16:35??label\aaa\mainwindow.h
?????文件????????1790??2018-06-24?16:35??label\aaa\mainwindow.ui
?????目錄???????????0??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\
?????文件???????21801??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\Makefile
?????文件??????176183??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\Makefile.Debug
?????文件??????175364??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\Makefile.Release
?????目錄???????????0??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\
?????文件??????156672??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\aaa.exe
?????文件?????????638??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\aaa.exe.em
?????文件??????????97??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\aaa.exe_manifest.rc
?????文件?????????704??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\aaa.exe_manifest.res
?????文件?????1179108??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\aaa.ilk
?????文件?????4509696??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\aaa.pdb
?????文件??????368404??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\labelpress.obj
?????文件??????339568??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\main.obj
?????文件??????500340??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\mainwindow.obj
?????文件????????4057??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\moc_labelpress.cpp
?????文件??????346535??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\moc_labelpress.obj
?????文件????????3633??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\moc_mainwindow.cpp
?????文件??????344638??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\debug\moc_mainwindow.obj
?????目錄???????????0??2018-06-24?16:49??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\release\
?????文件????????3479??2018-06-24?16:36??label\build-aaa-Desktop_Qt_5_3_MSVC2013_64bit-Debug\ui_mainwindow.h
評論
共有 條評論