⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialog.cpp

📁 Photo frame code for anyone,it s coding by C++.
💻 CPP
字号:
#include "dialog.h"
#include <qtimer.h>
#include <qpixmap.h>
#include <qstring.h>
#include <iostream>
#include <qpushbutton.h>

#include <qimage.h>

using std::cout;
using std::endl;

ShowJpeg :: ShowJpeg( QWidget *parent, const char *name )
      : QWidget( parent, name )
{
  QPixmap pm;

 /*widgetJpeg = new QWidget(this,"widgetJpeg");*/
  setMinimumSize(QSize(472,230));
  setMaximumSize(QSize(472,230));

 // this->setFixedWidth(pm.width());
 // this->setFixedHeight(pm.height());
  l=new QLabel( this,"label");
  
  autoShowTimer = new QTimer(this,"show handler");
  
  pushButton1 = new QPushButton( this, "pushButton1" );
  pushButton1->setGeometry( QRect( 118, 190, 118, 40 ) );
  connect( pushButton1, SIGNAL(clicked()), this, SLOT(forward()) );
    
  pushButton2 = new QPushButton( this, "pushButton2" );
  pushButton2->setGeometry( QRect( 0, 190, 118, 40) );
  connect( pushButton2, SIGNAL(clicked()), this, SLOT(backward()) );
  
  pushButton3 = new QPushButton( this, "pushButton3" );
  pushButton3->setGeometry( QRect( 236, 190, 118, 40 ) );
  connect( pushButton3, SIGNAL(clicked()), this, SLOT(timerlink()) );

  pushButton4 = new QPushButton( this, "pushButton4" );
  pushButton4->setGeometry( QRect( 354, 190, 118,40 ) );
  connect( pushButton4, SIGNAL(clicked()), this, SLOT(timerstop()) );

  
  pushButton1-> setText(tr(">"));
  pushButton2-> setText(tr("<"));
  pushButton3-> setText(tr(">>"));
  pushButton4-> setText(tr("x"));

}

void ShowJpeg :: forward()
{  
  count ++;
  if(count>=6)
  count=0;
  /*string str;
  str = static_cast<string>(count) + ".jpg";*/
  QString str;
  str = str.setNum(count) + ".jpg";
  cout<<str<<endl;
  QPixmap pixmap;
  
  pixmap.load(str);
    l->setGeometry(QRect(0,0,472,190));
    l->setPixmap(pixmap);
    l->setAlignment(AlignCenter);
    l->setScaledContents(TRUE);
   // l->adjustSize ();
   // l->setAutoResize (TRUE);
         
}

void ShowJpeg :: timerlink()
{
  connect( autoShowTimer, SIGNAL(timeout()), this, SLOT(update()) );
  autoShowTimer->start(2000);

}


void ShowJpeg :: update()
{
  
  count ++;
  if(count>=6)
  count=0;

  /*string str;
  str = static_cast<string>(count) + ".jpg";*/
  QString str;
  str = str.setNum(count) + ".jpg";
  cout<<str<<endl;
  QPixmap pixmap;

  pixmap.load(str);
    l->setGeometry(QRect(0,0,472,190));
    l->setPixmap(pixmap);
    l->setAlignment( AlignCenter );
    l->setScaledContents ( TRUE );
    // l->adjustSize ();
    // l->setAutoResize ( TRUE );
}


void ShowJpeg :: timerstop()
{
  autoShowTimer->stop();
}
                                                                                
                                                                                
void ShowJpeg :: backward()
{
  
  if(count>0)
  count--;
  else count=5;
  /*string str;
  str = static_cast<string>(count) + ".jpg";*/
  QString str;
  str = str.setNum(count) + ".jpg";
  cout<<str<<endl;
  QPixmap pixmap;

  pixmap.load(str);
    l->setGeometry(QRect(0,0,472,190));
    l->setPixmap(pixmap);
    l->setAlignment( AlignCenter );
    l->setScaledContents ( TRUE );
    //l->adjustSize ();
    /*l->setAutoResize ( TRUE );*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -