>> Features:
(1) Image switch Browse, previous/Next.
(2) Enlarge and reduce the image. Includes two mechanisms: mouse wheel and button zoom/Zoom out.
(3) The picture is automatically looped back. When you click Play, the other actions are not valid until you click Pause.
(4) When the image is zoomed in/out, click Restore or switch image to automatically revert to the default size.
>> Final effect:
(1) Click the play button:
(2) After the pause, click on the next one:
(3) Click to enlarge (or scroll the mouse wheel forward):
(4) Click to restore:
(5) Click to zoom Out (or slide the mouse wheel back):
(6) Click on the previous one:
(7) Click to rotate:
(8) Click to zoom Out (or the mouse wheel backwards):
(9) Click to restore:
>> Program:
Mypictureview.h
#ifndef Mypictureview_h#defineMypictureview_h#include<QWidget>#include<QVector>#include<QPixmap>#include<QTimer>#include<QFileDialog>#include<QString>#include<QLabel>#include<QWheelEvent>namespaceUi {classMypictureview;}classMypictureview: Publicqwidget{Q_object Public: Mypictureview (Qvector<qpixmap *> &pictures); ~Mypictureview ();PrivateSlots:voidon_btn_prev_clicked (); voidon_btn_spin_clicked (); voidon_btn_play_stop_clicked (); voidon_btn_orig_clicked (); voidon_btn_next_clicked (); voidon_btn_big_clicked (); voidon_btn_smal_clicked (); voidWheelevent (Qwheelevent *Event); voidPic_showloop ();Private: Ui::mypictureview*UI; Qvector<qpixmap *> &Pictures_; Qtimer*timer; QPIXMAP pix; Qlabel*label; voidPic_show1 (); voidPic_show2 (); BOOLisplaying; floatScale ; intsize; intCurrentindex; intImageangle;};#endif //Mypictureview_h
mypictureview.h
Mypictureview.cpp
#include"mypictureview.h"#include"ui_mypictureview.h"Mypictureview::mypictureview (Qvector<qpixmap *> &pictures): Pictures_ (Pictures), UI (NewUi::mypictureview) {UI->SETUPUI ( This); Scale=1; Currentindex=0;//Current Picture indexSize =pictures_.size (); IsPlaying=false; Imageangle=0; Label=NewQlabel; UI->scrollarea->setwidget (label); UI->scrollarea->setalignment (Qt::aligncenter);//display position, alignmentTimer=NewQtimer; Timer->setinterval (2* +);//2sConnect (timeout ()), timer,signal This, SLOT (Pic_showloop ())); Label-setalignment (Qt::aligncenter); if(Size >0) Pic_show1 ();} Mypictureview::~Mypictureview () {DeleteUI;}voidMypictureview::on_btn_prev_clicked ()//the previous one{Timer-Stop (); Scale=1; Imageangle=0; Currentindex--; if(currentindex<0) Currentindex=size-1; Pic_show1 ();}voidMypictureview::on_btn_spin_clicked ()//Rotate{Imageangle+=1; Imageangle= imageangle%4; Pic_show2 ();}voidMypictureview::on_btn_play_stop_clicked ()//play, pause, interval 2s{isplaying= !isplaying; if(isplaying) {UI->btn_play_stop->settext (TR ("Pause")); Timer-start (); UI->btn_big->setenabled (false); UI->btn_next->setenabled (false); UI->btn_orig->setenabled (false); UI->btn_prev->setenabled (false); UI->btn_smal->setenabled (false); UI->btn_spin->setenabled (false); } Else{UI->btn_play_stop->settext (TR ("Play")); Timer-Stop (); UI->btn_big->setenabled (true); UI->btn_next->setenabled (true); UI->btn_orig->setenabled (true); UI->btn_prev->setenabled (true); UI->btn_smal->setenabled (true); UI->btn_spin->setenabled (true); }}voidMypictureview::on_btn_orig_clicked ()//Restore{Timer-Stop (); Scale=1; Imageangle=0; Pic_show1 ();}voidMypictureview::on_btn_next_clicked ()//Next One{Timer-Stop (); Scale=1; Imageangle=0; Currentindex++; if(currentindex>size-1) Currentindex=0; Pic_show1 ();}voidMypictureview::on_btn_big_clicked ()//Zoom in{Timer-Stop (); Scale= scale*1.25;//corresponds to 0.8, zoom in and zoom out the same time, will revert to the original look if(Imageangle! =0) Pic_show2 (); ElsePic_show1 ();}voidMypictureview::on_btn_smal_clicked ()//Zoom Out{Timer-Stop (); Scale= scale*0.8; if(Imageangle! =0) Pic_show2 (); ElsePic_show1 ();}voidMypictureview::wheelevent (Qwheelevent *Event)//Wheel zoom in or out{ intnum =Event-Delta (); if(!isplaying) { if(Num >0) on_btn_big_clicked (); Elseon_btn_smal_clicked (); }}voidMypictureview::p Ic_show1 ()//Show Pictures{pix= (*pictures_[currentindex]). Scaled (640*scale, the*scale,qt::keepaspectratio); Label-setpixmap (PIX);}voidMypictureview::p ic_show2 ()//the display after rotation{Qmatrix Leftmatrix; Leftmatrix.rotate ( -*imageangle); Pix= (*pictures_[currentindex]). Scaled (640*scale, the*scale,qt::keepaspectratio); Label-Setpixmap (pix.transformed (leftmatrix,qt::smoothtransformation));}voidMypictureview::p Ic_showloop ()//Cycle through pictures{ Scale=1; Currentindex++; if(Currentindex > size-1) Currentindex=0; Pic_show1 ();}
Mypictureview.cpp
Main.cpp
#include"mypictureview.h"#include<QApplication>intMainintargcChar*argv[]) {Qapplication A (argc, argv); Qvector<qpixmap *>Pictures; Pictures.push_back (NewQpixmap (":/PICTURES/1")); Pictures.push_back (NewQpixmap (":/pictures/2")); Pictures.push_back (NewQpixmap (":/pictures/3")); Pictures.push_back (NewQpixmap (":/pictures/4")); Pictures.push_back (NewQpixmap (":/PICTURES/5")); Pictures.push_back (NewQpixmap (":/PICTURES/6")); Pictures.push_back (NewQpixmap (":/pictures/7")); Pictures.push_back (NewQpixmap (":/pictures/8")); Mypictureview view (Pictures); //Disable Maximize and Minimize buttonview.setwindowflags (view.windowflags ()& ~Qt::windowmaximizebuttonhint& ~qt::windowminimizebuttonhint); View.show (); returna.exec ();}
main.cpp
Resources:
Simple image Browser for Qt on Ubuntu