设为首页 加入收藏

TOP

用QT实现类似QQ截图的工具(二)
2014-11-24 07:54:04 来源: 作者: 【 】 浏览:2
Tags:实现 类似 截图 工具
hotScreenLabel->addAction(savePixmap);
shotScreenLabel->setContextMenuPolicy(Qt::ActionsContextMenu);
}


void Widget::createConnects()
{
//主窗口信号槽*****************************************************************


connect(ui->pbtnShot, SIGNAL(clicked()), this, SLOT(grapWindowScreen()));
connect(ui->pbtnShotAndMin, SIGNAL(clicked()), this, SLOT(miniWindows()));
connect(ui->pbtnMin, SIGNAL(clicked()), this, SLOT(miniWindows()));


connect(savePixmap, SIGNAL(triggered()), this, SLOT(saveShotPixmap()));


//主窗口信号槽*****************************************************************


//托盘信号槽*******************************************************************


connect(restore, SIGNAL(triggered()), this, SLOT(restoreWindows()));
connect(mini, SIGNAL(triggered()), this, SLOT(miniWindows()));
connect(quit, SIGNAL(triggered()), this, SLOT(quitApplication()));


//托盘信号槽*******************************************************************
}


void Widget::createEventFilter()
{
fullScreenLabel->installEventFilter(this);
}


QString Widget::getSaveShotPixmap()
{
return QFileDialog::getSaveFileName(shotScreenLabel,
tr("Open Image"),
".",
tr("Image Files(*.JPG *.PNG)"));
}


void Widget::grapWindowScreen()
{
if (!fullScreenLabel)
{
fullScreenLabel = new QLabel();
}


//获取全屏截图fullScreenPixmap,并将其放入fullScreenLabel
fullScreenPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
fullScreenLabel->setPixmap(fullScreenPixmap);


//label全屏显示
fullScreenLabel->showFullScreen();
}


void Widget::miniWindows()
{
showMinimized();
grapWindowScreen();
}


void Widget::restoreWindows()
{
showNormal();
}


void Widget::quitApplication()
{
qApp->quit();
}


void Widget::saveShotPixmap()
{
QString fileName = getSaveShotPixmap();


if (!fileName.isNull())
{
fullScreenPixmap.save(fileName);
}


}


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下printf输出字符串的颜色 下一篇一个让桌面下雪的ruby 小程序 snow

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·每日一道面试题-多线 (2025-12-26 06:20:17)
·java项目中哪些地方 (2025-12-26 06:20:14)
·Java真的是要没落了 (2025-12-26 06:20:12)
·C++ Lambda表达式保 (2025-12-26 05:49:45)
·C++ Lambda表达式的 (2025-12-26 05:49:42)