URL 统一资源定位符
(Uniform Resource Locator,缩写为URL),又叫做网页地址,是互联网上标准的资源的地址(Address)。互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该怎么处理它。
SHOTSCRREN屏幕截图功能,可实现帧动画
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <QPixmap>
#include <QDesktopWidget>
#include <QMessageBox>//消息对话框
#include <QFileDialog>//文件对话框
#include <QDesktopServices>
#include <QClipboard>
#include <QDebug>
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
#include <QCursor>
#include <QProcess>
//storageLocation
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void contextMenuEvent(QContextMenuEvent *event);
private slots:
void on_newScreenShotButton_clicked();
void shotScreenSlot();
void savePictureSlot();//保存截图
void startNotepadSlot();
private:
Ui::MainWindow *ui;
QTimer *timer;
QPixmap pixmap;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->savePictureButton, SIGNAL(clicked()), this, SLOT(savePictureSlot()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_newScreenShotButton_clicked()
{
if (ui->checkBox->isChecked())
{
this->hide();//this->show();
this->timer = new QTimer;
QObject::connect(this->timer, SIGNAL(timeout()), SLOT(shotScreenSlot()));
this->timer->start(ui->spinBox->value() * 1000);//控制延时时间,由spinBox的值控制
//this->timer->start(1000);
}
else
{
qApp->beep();//泵的一声
}
}
void MainWindow::shotScreenSlot()
{
this->pixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
ui->screenLable->setPixmap(this->pixmap.scaled(ui->screenLable->size()));
QClipboard *clipboard = QApplication::clipboard();//截图到剪切板
// QString originalText = clipboard->text();
// qDebug() << "current clipboard text is " << originalText;
clipboard->setPixmap(this->pixmap);//系统剪切板中就有图片的信息了,可以直接粘贴发送给别人
this->show();
this->timer->stop();
}
void MainWindow::savePictureSlot()
{
QString fileName = QFileDialog::getSaveFileName(this, "Save File", QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
this->pixmap.save(fileName);
}
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = new QMenu(this);
QAction *action = new QAction(this);//鼠标右键可以显示功能菜单(第一个功能)
QAction *processAction = new QAction(this);//鼠标右键可以显示功能菜单(第二个功能)
QObject::connect(processAction, SIGNAL(triggered()), this, SLOT(startNotepadSlot()));
QObject::connect(action, SIGNAL(triggered()), this, SLOT(savePictureSlot()));
action->setText("Save As");
processAction->setText("start notepad");
menu->addAction(action);//添加动作
menu->addSeparator();
menu->addAction(processAction);
menu->exec(QCursor::pos());
}
void MainWindow::startNotepadSlot()
{
QProcess *process = new QProcess;
process->start("notepad.exe");
}
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
PLAYER屏幕监控播放功能
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>//定时器
#include <QClipboard>//剪切板
#include <QPixmap>//图片
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QPixmap pixmap;
QTimer *timer;
private slots:
void fetchPictureSlot();
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->timer = new QTimer;
QObject::connect(this->timer, SIGNAL(timeout()), this, SLOT(fetchPictureSlot()));
this->timer->start(200);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::fetchPictureSlot()
{
QClipboard *board = QApplication::clipboard();
this->pixmap = board->pixmap();//获取图片
ui->playerLabel->setPixmap(this->pixmap.scaled(ui->playerLabel->size()));//设置图片大小
}
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}