#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDesktopWidget>
#include <QFileDialog>
#include <QScreen>
#include <QDir>
#include <QClipboard>
#include <QDebug>
#include <QCursor>
#include <QProcess> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::on_newPicButton_clicked()
{
if (ui->radioButtonHide->isChecked()) {
timer = new QTimer();
//timer->setInterval(ui->spinBox->value()*1000); //this->hide();
timer->start(/);
//int id = startTimer(ui->spinBox->value()*1000);
connect(this->timer,&QTimer::timeout,this,[=]{
//QDesktopWidget w;
m_pic = QPixmap::grabWindow(QApplication::desktop()->winId()); // 保存到剪切版
//QClipboard *clipboard = QGuiApplication::clipboard(); // QString originalText = clipboard->text();
// qDebug() << originalText;
//clipboard->setPixmap(m_pic); QSize size = ui->labelShowPic->size();
ui->labelShowPic->setPixmap(m_pic.scaled(size));
//timer->stop();
//this->show();
}); }
else {
qApp->beep();// 嘀嘀响
}
} void MainWindow::on_savePicButton_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
QDir::currentPath(),
tr("Images (*.png *.xpm *.jpg)")); if (!fileName.isEmpty()) {
m_pic.save(fileName);
} } void MainWindow::on_exitButton_clicked()
{
this->close();
} void MainWindow::contextMenuEvent(QContextMenuEvent *e)
{
QMenu *menu = new QMenu(this);
QAction *action = new QAction(this);
QAction *startNotePad = new QAction(this); connect(action,&QAction::triggered,this,&MainWindow::on_savePicButton_clicked);
connect(startNotePad,&QAction::triggered,this,&MainWindow::startNotePad); action->setText("Save as");
startNotePad->setText("startNotePad");
menu->addAction(action);
menu->addAction(startNotePad);
menu->exec(QCursor::pos());
} void MainWindow::startNotePad()
{
QProcess *p = new QProcess();
p->start("notepad.exe");
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <QTimer>
#include <QPixmap>
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); private slots:
void on_newPicButton_clicked(); void on_savePicButton_clicked(); void on_exitButton_clicked(); void contextMenuEvent(QContextMenuEvent *e); void startNotePad(); private:
Ui::MainWindow *ui; QTimer *timer;
QPixmap m_pic;
}; #endif // MAINWINDOW_H

contextMenuEvent的更多相关文章

  1. QMenu,contextmenuevent,窗体透明

    void MainWindow::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu=newQMenu; menu->addActi ...

  2. 关于tkCommand的各种事件的解释

    superclass for callback/observer methods vtkCommand is an implementation of the observer/command des ...

  3. QTableWidget详解(样式、右键菜单、表头塌陷、多选等)

    在Qt的开发过程中,时常会用到表单(QTableWidget)这个控件,网上的资料不少,但是都是最基本的,有一些比较经常遇到的问题也说得不太清楚.所以,今天就在这里总结一下! 以下为个人模拟Windo ...

  4. 利用Flex组件birdeye绘制拓扑关系图

    birdeye绘制拓扑关系图 1.flex简单介绍 Flex 是一个高效.免费的开源框架,可用于构建具有表现力的 Web应用程序,这些应用程序利用Adobe Flash Player和Adobe AI ...

  5. Flex contextMenu

    没想到再这里也要跌跌撞撞. 这个东西我很久之前就懂了的啊! 最开始是这么写的: private function init():void { var contextMenu:ContextMenu = ...

  6. QTableWidget详解(样式、右键菜单、表头塌陷、多选等) 2013-10-23 10:54:04

    一.设置表单样式 点击(此处)折叠或打开 table_widget->setColumnCount(4); //设置列数 table_widget->horizontalHeader()- ...

  7. 【转载】Pyqt 添加右键菜单方法

    转载地址: http://www.cnblogs.com/yogalau/p/3954042.html?utm_source=tuicool QListWidget 是继承 QWidget 的, 所以 ...

  8. 关于QT的系统总结

    编译环境与开发流程 开发QT有两种IDE可以使用,一种是使用 VS + Qt 的插件,另一种就是使用QtCreator工具.前一种是微软的工具,用的都比较多容易上手,缺点是信号槽的支持不太好,需要手写 ...

  9. Qt之QAbstractItemView右键菜单

    一.功能概述 说起右键菜单,之前Qt之自定义QLineEdit右键菜单这篇文章中我已经讲述过3种右键菜单的实现方式,今儿也是在啰嗦一下,针对QListWidget类在定制一下右键菜单,我使用的具体方式 ...

随机推荐

  1. Android--Bitmap处理、圆角、圆形

    /** * 转换图片成圆形 * * @param bitmap * 传入Bitmap对象 * @return */ public static Bitmap toRoundBitmap(Bitmap ...

  2. 结合consul raft库理解raft

    一 入口 github.com/hashicorp/consul/agent/consul/server.go func (s *Server) setupRaft() error { 状态机,用于c ...

  3. Redis安装--CentOS7上安装Redis

    echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加echo微信(微信号:t2421499075)交流学习. 百战不败,依不自称常胜,百败不颓,依能奋力前行.--这才是真正的堪称强大!!! 1.R ...

  4. Linux 下 maven 的下载、上传与安装

    要运行maven,必须要有 JDK ,maven 是由 Java 语言编写的 一.JDK 的安装 ORACLE 官网下载JDK jdk-8u231-linux-x64.tar.gz 上传 JDK 至 ...

  5. 从 SimpleIntegerProperty 看 Java属性绑定(property binding) 与 观察者模式(Observable)

    //TODO:ExpressionHelper .bindBidirectional双向绑定.以及IntegerExpression的一系列算术方法和返回的IntegerBinding暂未详细解析(比 ...

  6. C++线程同步之临界区

    #include <iostream> #include <windows.h> using namespace std; CRITICAL_SECTION cs; // Lo ...

  7. 批量改主机名报错:Address 192.168.43.117 maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

    ssh连接批量修改主机名报出以下提示: [root@bqh-nfs- ~]# vim modfilyhostname.sh [root@bqh-nfs- ~]# sh modfilyhostname. ...

  8. sqlserver存储过程里传字段、传字符串,并返回DataTable、字符串,存储过程调用存储过程。

    经常需要查一些信息,  想写视图来返回数据以提高效率,但是用试视图不能传参,只好想到改存储过程.记录一下语法,方便以后做项目时候想不起来了用. 1:传字段返回datatable 2: 传字段回一串字符 ...

  9. Linux命令cut

    原文 cut 文件内容查看 显示行中的指定部分,删除文件中指定字段 显示文件的内容,类似于下的type命令. 说明 该命令有两项功能,其一是用来显示文件的内容,它依次读取由参数file所指明的文件,将 ...

  10. Linux之项目的部署

    前期准备 python3解释器 uwsgi wsgi(web服务网关接口,就是一个实现了python web应用的协议) virtualenvwrapper 路飞的代码 vue的代码 nginx (一 ...