QT实现截图效果显示

当界面上点击一个按钮,实现截图功能之后,需要反馈给用户一个截图成功的提示。模仿Iphone截图显示。话不多说直接上代码。
头文件

class QPropertyAnimation;
class BlinkFrame : public QFrame
{
	Q_OBJECT

public:
	explicit BlinkFrame(QWidget *parent = 0);
	~BlinkFrame();
	void setSnapshotPixmap(QPixmap &pixmap);
	void show(); 
	void setInitRect(QRect rect);
private:
	QLabel* mBGLabel;
	QRect mRect;
	QPixmap mFitpixmap;
	QPropertyAnimation* mShowAnimal{ nullptr };
};

源文件


BlinkFrame::BlinkFrame(QWidget *parent) :
    QFrame(parent)
{
	setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
	setAttribute(Qt::WA_TranslucentBackground, true);
	//setWindowOpacity(0.8);
	mBGLabel = new QLabel(this);
	mBGLabel->setStyleSheet("background-color:white");
	mShowAnimal = new QPropertyAnimation(mBGLabel, "geometry");
}

BlinkFrame::~BlinkFrame()
{

}

void BlinkFrame::setSnapshotPixmap(QPixmap &pixmap)
{
	mFitpixmap = pixmap;
}
void BlinkFrame::show()
{
	mShowAnimal->setDuration(400);
	mShowAnimal->setStartValue(mRect);
	mShowAnimal->setEndValue(QRect(mRect.x(), mRect.y() + mRect.height()*0.7, mRect.width()*0.3, mRect.height()*0.3));
	connect(mShowAnimal, &QPropertyAnimation::finished, this, [=](){
		mFitpixmap = mFitpixmap.scaled(mBGLabel->width(), mBGLabel->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
		mBGLabel->setPixmap(mFitpixmap);
		mBGLabel->setAlignment(Qt::AlignCenter);
		QTimer::singleShot(900, [=](){
			hide();
			this->deleteLater();
		});
	});
	QDesktopWidget* desktop = QApplication::desktop();
	int count = desktop->screenCount();
	int tempWidth = 0;
	int tempHeight = 0;
	for (int i = 0; i < count; i++)
	{
		tempWidth += desktop->screenGeometry(i).width();
	}
	if (count > 0)
	{
		tempHeight = desktop->screenGeometry(0).height();
	}
	this->setGeometry(0, 0, tempWidth, tempHeight);
	QFrame::show();
	//QFrame::showFullScreen();
	mBGLabel->resize(mRect.size());
	mBGLabel->move(mRect.x(), mRect.y());
	mShowAnimal->start();
}

void BlinkFrame::setInitRect(QRect rect)
{
	mRect = rect;
}

应用代码:

BlinkFrame *blinkLabel = new BlinkFrame;
blinkLabel->setInitRect(m_previewRect);
blinkLabel->setSnapshotPixmap(QPixmap("./ScreenSnap.png"));
blinkLabel->show();
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值