window.cpp

来自「基于QT的数码相框」· C++ 代码 · 共 54 行

CPP
54
字号
#include "window.h"
#include<QtGui>
window::window(QWidget *parent):QWidget(parent)
{
    next= new QPushButton(tr("NEXT"));
    prev= new QPushButton(tr("PREV"));
    this->setFocus(Qt::ActiveWindowFocusReason);
    QHBoxLayout *hlayout = new QHBoxLayout;
    hlayout->addWidget(next);
    hlayout->addWidget(prev);
    QVBoxLayout *vlayout = new QVBoxLayout;
    pic = new picture;
    vlayout->addWidget(pic);
    vlayout->addLayout(hlayout);
    setLayout(vlayout);
    setWindowTitle(tr("PICTURE"));
    //setFixedHeight(sizeHint().height());
    //std::cout<<"the key baoad"<<press.key ();

    connect(next,SIGNAL(clicked()),this,SLOT(nextpicture()));
    connect(prev,SIGNAL(clicked()),this,SLOT(prevpicture()));
    //connect(,SIGNAL(key()),   this,SLOT(prevpicture()));

}
 void window::keyPressEvent(QKeyEvent *event)
{
     switch(event->key())
     { case Qt::Key_Right:      nextpicture(); break;
       case Qt::Key_Left:       prevpicture(); break;
       case Qt::Key_Up:         prevpicture(); break;
       case Qt::Key_Down:       nextpicture(); break;
       case 65:   zoomout(); break;
       case 68:   zoomin(); break;
     }
     qDebug()<<"key press"<<event->key();

}
 void window::zoomin()
 {
      pic->changerect(true,true);
 }
 void window::zoomout()
 {
      pic->changerect(false,true);
 }
void window::nextpicture()
{
     pic->next();
}
void window::prevpicture()
{
     pic->prev();
}

⌨️ 快捷键说明

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