setWindowFlags(Qt::WindowStaysOnTopHint|Qt::ToolTip);
setWindowState(Qt::WindowActive|Qt::WindowFullScreen);//全屏无框架显示且处于激活状态
resize(qApp->desktop()->rect().size());
QPolygon vt_pos; //定义多边形
bgpixmap=QPixmap::grabWindow(QApplication::desktop()->winId());//抓取当前屏幕的图片
paintEvent(QPaintEvent *event)
{
painter.begin(this);//进行重绘
painter.drawPixmap(0,0,loadpixmap);//将背景图片画到窗体上
painter.setPen(QPen(Qt::blue,2,Qt::SolidLine,Qt::FlatCap));//设置画笔
painter.drawPolygon(vt_pos);
painter.end();
}
mouseMoveEvent(QMouseEvent *event)
{
vt_pos.push_back(event.pos);//将鼠标经过的点入栈
}
mouseReleaseEvent(QMouseEvent *event)
{
/*手动绘图*/
path.addPolygon(vt_pos);
path.setFillRule(Qt::WindingFill);//设置填充规则(和setClipPath()配合)
QRectFrf=path.controlPointRect();//获取路径所在矩形区域
QPixmapmap;
map=loadpixmap.copy(rf.topLeft().x(),rf.topLeft().y(),rf.width(),rf.height());
//坐标转换以(0-rf.topLeft().x(),0-rf.topLeft().y()为坐标原点)
QPainterPathpa=path.translated(0-rf.topLeft().x(),0-rf.topLeft().y());
//创建QPixmap设备,将需要的区域map绘到QPixmap上
temp_image=QPixmap(rf.width(),rf.height());
//temp_image.fill(Qt::transparent);
temp_image.fill(QColor(255,255,255));
temp_paint.begin(&temp_image);
temp_paint.setClipping(true);
temp_paint.setClipPath(pa);//设置裁剪路径
temp_paint.drawPixmap(0,0,map);
temp_paint.setClipping(false);
temp_paint.end();
shotPixmap=temp_image;//.copy(0,0,rf.width(),rf.height());//更新选区的Pixmap
}