IMX283 QT4.73電子相冊

IMX283 QT4.73電子相冊

前言

繫上一篇移植了4.13以後,板子上有個顯示屏,天天放着感覺浪費,就想做個顯示圖片的,額,正好zlg的文件系統有Qt4.7.3所以就直接做了一個,啥都不說了,先上展示圖,由於只能5M,湊合着看~
在這裏插入圖片描述
另外加了網絡更新時間:
在這裏插入圖片描述
參考鏈接:
https://blog.svenhetin.com/linuxxia-c-huo-qu/

開始

環境用的zlg的開發qt環境,然後其實就是qt那一套,嘗試過命令行輸出圖片路徑,但是不知道爲啥在開發板上就不行,然而在主機上卻可以,後來直接寫死了,在執行文件下的當前目錄下建立一個src目錄,然後把圖像複製進去就OK了,主函數如下:

QString imgPath = "./src/";
QStringList imgList;
QDir imgDir;
int img_cnt = 0;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //if(argc >= 2){
    //    imgPath = QString(argv[2]);
    //}

    if(!imgPath.isEmpty()){
        imgDir = QDir(imgPath);
        imgList << "*bmp"<<"*.jpg"<<"*.png";
        imgDir.setNameFilters(imgList);
        img_cnt = imgDir.count();
    }

    elcPicture w;
    w.show();

    return a.exec();
}

主要就是在窗口建立之前讀取src目錄下的所有圖像,然後析構函數:

#define TIME_TICK 4000

elcPicture::elcPicture(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::elcPicture)
{
    ui->setupUi(this);
    ui->setupUi(this);

    ui->img_widget->setCursor(Qt::BlankCursor);//圖像窗口不要光標

    animation = NULL;
    animation1 = NULL;

#if 1
    this->showFullScreen();//全屏顯示
    this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);//不要windows的 _ [] x
#endif
    if(img_cnt > 0){//有圖像初始化定時器,4s一張圖像
        timer = new QTimer(this);
        img = new QImage();
        this->imgCnt = img_cnt;
        curCnt = 0;
        connect(timer, SIGNAL(timeout()), this, SLOT(ontimeHandle()));
        ontimeHandle();
        timer->start(TIME_TICK);

        //ontimeHandle();
/*
        QString imgName = imgDir[curCnt++];

        if(img->load(imgPath + imgName)){
            ui->info_label->setText(imgName);
            *img = img->scaled(ui->img_label->width(), ui->img_label->height());
            ui->img_label->setPixmap(QPixmap::fromImage(*img));
        }
        */
    }else{//沒有圖像
        ui->info_label->setText("Sorry No Input In Dir src");\
        //ui->img_label->setPixmap(QPixmap(":/Resources/hj.jpg"));
    }

}

代碼解釋都在上面了,自己可以理解感覺
下面是定時處理

void elcPicture::ontimeHandle()
{
    if(curCnt == imgCnt)
        curCnt = 0;

    QString imgName = imgDir[curCnt++];

    if(animation == NULL){
        label = new QLabel(ui->img_widget);
        animation = new QPropertyAnimation(label, "geometry");
    }else
        animation->stop();

    if(img->load(imgPath + imgName)){
        ui->info_label->setText(imgName);
        *img = img->scaled(ui->img_label->width(), ui->img_label->height());
        
        label->resize(ui->img_label->size());
        label->setPixmap(QPixmap::fromImage(*img));
        label->show();
    }

    animation->setDuration(800);
    animation->setEndValue(ui->img_label->geometry());
    animation->setStartValue(QRect(-ui->img_label->width(), 0, ui->img_label->width(), ui->img_label->height()));
    animation->start();
}

上面是從左切入的動畫,然後顯示下一張圖像,然後下面是顯示更新時間form,然後處理label消息的函數

void elcPicture::showTimeInfo(){
    if(timeWiget){
        timeWiget->close();
        delete timeWiget;
        timeWiget = NULL;
    }
    timeWiget = new timeInfo();
    timeWiget->show();
    timeWiget->move((this->width() - timeWiget->width())/2, (this->height() - timeWiget->height())/2);
}


bool elcPicture::eventFilter(QObject *obj, QEvent *event){
    if(obj == ui->info_label){
        if(event->type() == QEvent::MouseButtonPress){
           // QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
           // if(mouseEvent->button() == Qt::LeftButton){
                showTimeInfo();
                return true;
           // }
           // else
           //     return false;
        }else
            return false;
    }else{
        return QMainWindow::eventFilter(obj, event);
    }
}

此外要注意網絡連接新加一個單獨的線程進行處理,否則堵塞主界面線程,繼承重寫QThread的run,如下:

void mThread::run(){
    ntpdate(&pm);
    stopFlag = true;
}

然後在啓動的時啓動線程更新

END

lrz到開發板,改權限chmod +x xxx
執行:./xxx -qws
純QT,還是有點意思~
不在是搬磚了這個板子,不過還是zynq好玩~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章