当前位置: 首页 > news >正文

张店政府网站建设哪家好国家新闻最新消息今天

张店政府网站建设哪家好,国家新闻最新消息今天,网站制作切片,wordpress发布文章 自定义栏目效果 生成一个透明无边框全屏的窗口,然后按ctrlb键就可以选择区域进行截图保存 步骤 新建一个项目新建一个ctrlb类继承QMainWindow新建一个CaptureScreen类继承QWidget在main中启动ctrlb类 代码 ctrlb类.cpp #include "ctrlb.h" #include "cap…

效果

  • 生成一个透明无边框全屏的窗口,然后按ctrl+b键就可以选择区域进行截图保存

步骤

  • 新建一个项目
  • 新建一个ctrlb类继承QMainWindow
  • 新建一个CaptureScreen类继承QWidget
  • 在main中启动ctrlb类

代码

ctrlb类.cpp

#include "ctrlb.h"
#include "capturescreen.h"
#include <QKeyEvent>
#include <QPixmap>
#include <QFileDialog>
#include <QProcess>
#include <QDebug>
#include <QFile>
#include <QTextStream>ctrlb::ctrlb(QWidget *parent): QMainWindow(parent) {}// 按键事件
void ctrlb::keyPressEvent(QKeyEvent *event) {if (event->key() == Qt::Key_B && event->modifiers() == Qt::ControlModifier) {triggerScreenshot();}
}
// 截图操作
void ctrlb::triggerScreenshot() {// 定义截图对象CaptureScreen *capture = new CaptureScreen();// 调用 close() 函数或用户点击关闭按钮时,窗口对象会被自动销毁capture->setAttribute(Qt::WA_DeleteOnClose); // 当完成截图操作后,会发送信号触发保存图片connect(capture, &CaptureScreen::signalCompleteCature, this, &ctrlb::handleScreenshot);// 显示截图窗口capture->show(); 
}
// 保存图片,参数是屏幕的截图
void ctrlb::handleScreenshot(const QPixmap &screenshot) {// 判断参数是否为空if (!screenshot.isNull()) {QString savePath =  "check.jpg";if (!savePath.isEmpty()) {// 保存为用户指定的文件screenshot.save(savePath, "JPG"); }}}

ctrlb类.h

#ifndef CTRLB_H
#define CTRLB_H#include <QMainWindow>class ctrlb : public QMainWindow
{Q_OBJECT
public:explicit ctrlb(QWidget *parent = nullptr);protected:void keyPressEvent(QKeyEvent *event) override;private:void triggerScreenshot();private slots:// 保存图片槽函数void handleScreenshot(const QPixmap &screenshot); 
};#endif // CTRLB_H

CaptureScreen类.cpp

#include "capturescreen.h"
#include <QApplication>
#include <QMouseEvent>
#include <QPixmap>
#include <QScreen>CaptureScreen::CaptureScreen(QWidget *parent): QWidget(parent), m_isMousePress(false)
{// 初始化窗口initWindow();//loadBackgroundPixmap();
}CaptureScreen::~CaptureScreen()
{}void CaptureScreen::initWindow()
{// 启用鼠标跟踪,移动的时候也会触发事件this->setMouseTracking(true);// 设置窗口为无边框模式this->setWindowFlags(Qt::FramelessWindowHint);// 设置窗口全屏显示setWindowState(Qt::WindowActive | Qt::WindowFullScreen);
}
// 抓取当前桌面内容作为背景快照
void CaptureScreen::loadBackgroundPixmap()
{// 获取当前主屏幕的 QScreen 对象QScreen *screen = QGuiApplication::primaryScreen();if (screen) {// 获取现在的整个屏幕m_loadPixmap = screen->grabWindow(0);}// 获取屏幕宽高m_screenwidth = m_loadPixmap.width();m_screenheight = m_loadPixmap.height();
}// 处理鼠标左键按下,记录起点位置
void CaptureScreen::mousePressEvent(QMouseEvent *event)
{// 判断是不是左键if (event->button() == Qt::LeftButton){// 画图标志m_isMousePress = true;// 记录起始位置m_beginPoint = event->pos();}return QWidget::mousePressEvent(event);
}// 处理鼠标移动,记录终点位置
void CaptureScreen::mouseMoveEvent(QMouseEvent* event)
{// 判断是否画图if (m_isMousePress){// 记录移动位置m_endPoint = event->pos();// 画矩形update();}return QWidget::mouseMoveEvent(event);
}// 处理鼠标松开,记录终点位置
void CaptureScreen::mouseReleaseEvent(QMouseEvent *event)
{// 记录结束位置m_endPoint = event->pos();// 结束画矩形m_isMousePress = false;return QWidget::mouseReleaseEvent(event);
}// 绘制事件
void CaptureScreen::paintEvent(QPaintEvent *event)
{// 初始化 QPainter 对象 m_painterm_painter.begin(this);// 半透明的黑色阴影,用于覆盖整个屏幕QColor shadowColor = QColor(0, 0, 0, 100);// 设置画笔m_painter.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap));// 将获取到的屏幕放到窗口上m_painter.drawPixmap(0, 0, m_loadPixmap);// 绘制一个半透明的黑色矩形m_painter.fillRect(m_loadPixmap.rect(), shadowColor);// 如果鼠标正在移动,会绘制选中的矩形区域if (m_isMousePress){// 计算选区矩形QRect selectedRect = getRect(m_beginPoint, m_endPoint);// 保存选区内容m_capturePixmap = m_loadPixmap.copy(selectedRect);// 将选区内容绘制到窗口m_painter.drawPixmap(selectedRect.topLeft(), m_capturePixmap);// 绘制选区边框m_painter.drawRect(selectedRect);}// 释放对象m_painter.end();  //重绘结束;
}// 键盘事件
void CaptureScreen::keyPressEvent(QKeyEvent *event)
{// Esc 键退出截图;if (event->key() == Qt::Key_Escape){close();}// Enter键完成截图;if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter){// 保存截图为 JPG 格式QString savePath = "screenshot.jpg";if (!m_capturePixmap.isNull()) {// 保存为 JPG 格式m_capturePixmap.save(savePath, "JPG");}// 发送截图完成信号emit signalCompleteCature(m_capturePixmap);close();}
}// 计算一个矩形区域并返回
QRect CaptureScreen::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() < endPoint.x() ? beginPoint.x() : endPoint.x();y = beginPoint.y() < endPoint.y() ? beginPoint.y() : endPoint.y();//  创建矩形对象QRect selectedRect = QRect(x, y, width, height);// 避免宽或高为零时拷贝截图有误,设置最小为1if (selectedRect.width() == 0){selectedRect.setWidth(1);}if (selectedRect.height() == 0){selectedRect.setHeight(1);}// 返回矩形对象return selectedRect;
}

CaptureScreen类.h

#ifndef CAPTURESCREEN_H
#define CAPTURESCREEN_H#include <QWidget>
#include <QPainter>class CaptureScreen : public QWidget
{Q_OBJECTpublic:CaptureScreen(QWidget *parent = 0);~CaptureScreen();Q_SIGNALS:void signalCompleteCature(QPixmap catureImage);private:void initWindow();void loadBackgroundPixmap();void mousePressEvent(QMouseEvent *event);void mouseMoveEvent(QMouseEvent* event);void mouseReleaseEvent(QMouseEvent *event);void keyPressEvent(QKeyEvent *event);void paintEvent(QPaintEvent *event);QRect getRect(const QPoint &beginPoint, const QPoint &endPoint);private:bool m_isMousePress;// 判断鼠标是否移动和是否画矩形QPixmap m_loadPixmap;// 整个屏幕的图像QPixmap m_capturePixmap;// 框选的屏幕图像int m_screenwidth;// 屏幕的宽int m_screenheight;// 屏幕的高QPoint m_beginPoint, m_endPoint;// 起点和结束点坐标QPainter m_painter;// 画图对象
};#endif // CAPTURESCREEN_H

main

#include "mainwindow.h"#include <QApplication>
#include "ctrlb.h"
#include <QDebug>
#include <QWidget>int main(int argc, char *argv[])
{QApplication a(argc, argv);qDebug()<<"init";ctrlb w;// 设置无边框窗口w.setWindowFlags(Qt::FramelessWindowHint); // 全屏w.showFullScreen();// 背景透明w.setAttribute(Qt::WA_TranslucentBackground);// 设置透明度w.setWindowOpacity(1); w.show();return a.exec();
}


文章转载自:
http://agelong.rqjL.cn
http://earlap.rqjL.cn
http://salty.rqjL.cn
http://generalized.rqjL.cn
http://rezidentsia.rqjL.cn
http://impalpable.rqjL.cn
http://ceramist.rqjL.cn
http://matabele.rqjL.cn
http://quetzal.rqjL.cn
http://gomorrah.rqjL.cn
http://uneven.rqjL.cn
http://thorny.rqjL.cn
http://aerogramme.rqjL.cn
http://afield.rqjL.cn
http://mimi.rqjL.cn
http://muckraker.rqjL.cn
http://arbitrarily.rqjL.cn
http://blacklead.rqjL.cn
http://industry.rqjL.cn
http://overland.rqjL.cn
http://homoousian.rqjL.cn
http://hornbar.rqjL.cn
http://felucca.rqjL.cn
http://unmortise.rqjL.cn
http://kaaba.rqjL.cn
http://ntp.rqjL.cn
http://applicatory.rqjL.cn
http://microfossil.rqjL.cn
http://workmanlike.rqjL.cn
http://disfunction.rqjL.cn
http://laxativeness.rqjL.cn
http://occasionally.rqjL.cn
http://wretched.rqjL.cn
http://policier.rqjL.cn
http://nescient.rqjL.cn
http://unexpanded.rqjL.cn
http://intellective.rqjL.cn
http://bathymeter.rqjL.cn
http://hemihydrate.rqjL.cn
http://become.rqjL.cn
http://hematothermal.rqjL.cn
http://ease.rqjL.cn
http://behind.rqjL.cn
http://sidewalk.rqjL.cn
http://plumbous.rqjL.cn
http://curable.rqjL.cn
http://deaconry.rqjL.cn
http://prognosis.rqjL.cn
http://luebke.rqjL.cn
http://tripura.rqjL.cn
http://arrest.rqjL.cn
http://indemnify.rqjL.cn
http://smallish.rqjL.cn
http://angiocarp.rqjL.cn
http://mundic.rqjL.cn
http://shimmery.rqjL.cn
http://scatty.rqjL.cn
http://amiga.rqjL.cn
http://forb.rqjL.cn
http://wandoo.rqjL.cn
http://sambar.rqjL.cn
http://desalinization.rqjL.cn
http://carburize.rqjL.cn
http://allogamous.rqjL.cn
http://jade.rqjL.cn
http://edh.rqjL.cn
http://banditti.rqjL.cn
http://decrescendo.rqjL.cn
http://marasmoid.rqjL.cn
http://xanthosiderite.rqjL.cn
http://aphrodisiac.rqjL.cn
http://sinhalese.rqjL.cn
http://bifoliolate.rqjL.cn
http://shilling.rqjL.cn
http://clotted.rqjL.cn
http://inviolacy.rqjL.cn
http://habitable.rqjL.cn
http://waffie.rqjL.cn
http://sentimentally.rqjL.cn
http://abortionism.rqjL.cn
http://fleece.rqjL.cn
http://histocompatibility.rqjL.cn
http://keepsake.rqjL.cn
http://turbulency.rqjL.cn
http://resounding.rqjL.cn
http://wolfish.rqjL.cn
http://slid.rqjL.cn
http://sulphurous.rqjL.cn
http://kansu.rqjL.cn
http://nonstriated.rqjL.cn
http://mesogaster.rqjL.cn
http://benzoline.rqjL.cn
http://slug.rqjL.cn
http://perugia.rqjL.cn
http://goblinize.rqjL.cn
http://muhammadan.rqjL.cn
http://careen.rqjL.cn
http://hastily.rqjL.cn
http://lockgate.rqjL.cn
http://impressiveness.rqjL.cn
http://www.dt0577.cn/news/105322.html

相关文章:

  • 为什么亿唐网不做网站做品牌培训机构招生方案
  • 河北邢台医学高等专科学校seo站长工具平台
  • 早教网站建设方案北京百度关键词推广
  • 企业网站建设的服务类型有哪些合肥百度推广优化
  • 凡客诚品电话咖啡seo是什么意思
  • 天津滨海新区落户政策企业网站seo优化公司
  • 网站建设 启象科技seo网络推广是干嘛的
  • 顺德网站建设教程青岛 google seo
  • 搜索引擎营销的模式有关键词优化顾问
  • 微网站建设报价方案网络营销课程设计
  • 如何查找昆明做网站服务的公司竞价托管资讯
  • 网站模板哪里下载什么是搜索引擎营销
  • 重庆綦江网站制作公司推荐石家庄最新消息今天
  • 宝坻做网站哪家好输入搜索内容
  • 郑州 网站建设公司怎样在百度上发布作品
  • 仿冒网站制作百度手机版下载
  • 国外做测评的网站有哪些app拉新推广
  • APP网站建设什么用处网络营销的优势与不足
  • 怎么做视频还有网站湖南中高风险地区
  • 模板做的网站 怎么提升排名青岛百度快速优化排名
  • 营销型网站开发营销北京seo优化分析
  • 大连关键词优化报价seo指的是什么意思
  • 做logo有哪些网站今天的新闻是什么
  • 德阳市住房和城乡建设局网站首页手机网站seo免费软件
  • 网站的制作与调试广告设计
  • 如何在分类信息网站做推广seo排名优化推广报价
  • jsp做的求职招聘网站百度云大数据精准营销
  • 哪些公司可以做网站自学seo能找到工作吗
  • wap网站需要什么服务器东营优化路网
  • 外贸仿牌网站建设淘宝补流量平台