最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Qt學(xué)習(xí):QPixmap實(shí)現(xiàn)的截屏程序代碼示例

重要函數(shù): 
1.bool isNull(); //判斷圖片是否為空白. 
2.bool save(QString); //圖片保存到參數(shù)的路徑. 
3.QPixmap grabWidget(WId,x=0,y=0,w=-1,h=-1); //截取圖片. 
4.void scaled(QSize); //把圖片按比例縮放.

成都創(chuàng)新互聯(lián)是一家專業(yè)提供撫順縣企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為撫順縣眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。

下面是一個(gè)簡單的截圖器的示例代碼:

首先從Qt設(shè)計(jì)師拖拽出如下界面,并且進(jìn)行布局. 
Qt學(xué)習(xí): QPixmap實(shí)現(xiàn)的截屏程序代碼示例


以下是”c.cpp下的代碼:”

#include "c.h"c::c(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);    //設(shè)置按鈕的圖標(biāo).可不設(shè)置.只是為了好看.
    ui.grabScreenButton->setIcon(QIcon("Icons/cut.png"));
    ui.saveButton->setIcon(QIcon("Icons/save.png"));    //設(shè)置按鈕的快捷鍵.
    ui.grabScreenButton->setShortcut(tr("Ctrl+G"));
    ui.saveButton->setShortcut(tr("Ctrl+S"));
    ui.cancelButton->setShortcut(tr("Ctrl+Q"));    //連接信號(hào)與槽.
    connect(ui.grabScreenButton, SIGNAL(clicked()), this, SLOT(cutScreenSlot()));
    connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(savePictureSlot()));
    connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(closeSlot()));
}

c::~c()
{

}//保存圖片的槽.void c::savePictureSlot()
{    if (this->isSaved)
        QMessageBox::information(this, "warning!", QString::fromLocal8Bit("沒有可以被保存的圖片!"));    else
    {        this->savePicture();
    }
}void c::cutScreenSlot()
{    //先隱藏窗口.
    this->hide();    //延遲3秒鐘.
    Sleep(3000);    //截取當(dāng)前屏幕的圖片.
    pixmap = QPixmap::grabWindow(QApplication::desktop()->winId());    //讓label框自動(dòng)填滿內(nèi)容.
    ui.label->setScaledContents(true);    //讓label框應(yīng)用圖片,并且自動(dòng)縮放像素.
    ui.label->setPixmap(pixmap.scaled(ui.label->size()));    this->isSaved = false;    //顯示窗口.
    this->show();
}void c::closeSlot()
{    if (this->isSaved)
    {        this->close();
    }    else
    {        //設(shè)置退出提示框.
        QMessageBox temp(QMessageBox::NoIcon, QString::fromLocal8Bit("是否要退出"), QString::fromLocal8Bit("你的圖片尚未保存,是否要保存?"));
        temp.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        temp.setButtonText(QMessageBox::Yes, QString::fromLocal8Bit("保存"));
        temp.setButtonText(QMessageBox::No, QString::fromLocal8Bit("退出"));        int status = temp.exec();        if (status == QMessageBox::Yes)
        {            this->savePicture();
        }        else if (status == QMessageBox::No)
        {            this->close();
        }
    }
}void c::closeEvent(QCloseEvent*event)
{
    closeSlot();
}void c::savePicture()
{    //調(diào)用文件的類.設(shè)置了標(biāo)題和路徑.
    QFileDialog temp(this, "Save Picture", "c:/users/administrator/desktop");    //修改模式為保存模式.
    temp.setAcceptMode(QFileDialog::AcceptSave);    //自動(dòng)添加后綴為"jpg".
    temp.setDefaultSuffix("jpg");    int status = temp.exec();    if (status == QDialog::Accepted)
    {
        QString path = temp.selectedFiles()[0];        //圖片保存到這個(gè)路徑里去.
        bool ok = pixmap.save(path);        if (ok)
            QMessageBox::information(this, QString::fromLocal8Bit("保存成功"), QString::fromLocal8Bit("圖片已成功保存!"));        this->isSaved = true;
    }
}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101

以下是”c.h下的代碼:”

#ifndef C_H#define C_H#include #include "ui_c.h"#include #include #include #include #include #include #include #include #include class c : public QMainWindow{
    Q_OBJECTpublic:
    c(QWidget *parent = 0);
    ~c();    void savePicture();private slots:    void cutScreenSlot();    void savePictureSlot();    void closeSlot();protected:    void closeEvent(QCloseEvent*event);private:
    Ui::cClass ui;
    QPixmap pixmap;    bool isSaved = true;
};#endif // C_H12345678910111213141516171819202122232425262728293031323334353637

最后是”main.cpp下的代碼:”

#include "c.h"#include int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    c w;
    w.show();    return a.exec();
}1234567891011


網(wǎng)頁名稱:Qt學(xué)習(xí):QPixmap實(shí)現(xiàn)的截屏程序代碼示例
文章分享:http://fisionsoft.com.cn/article/josccs.html