void Window::keyPressEvent(QKeyEvent* e){ if(e->key()==Qt::Key_Space) yes=true;///Здесь что то нужно дописать и как товызвать paintEvent ?///?????????????Как?}
void Window::paintEvent( QPaintEvent * ){ QPainter pip; pip.begin(this); pip.drawPixmap(0,0,QPixmap("img/screen.png")); pip.setBrush(QBrush(Qt::red,Qt::DiagCrossPattern)); pip.setPen(QPen(Qt::blue,3,Qt::DashLine)); pip.drawRect((QRect(10,10,30,30))); if(yes){ pip.drawPixmap(0,0,QPixmap("img/1.png")); //for(int i=1;i<=7;i++); //pip.drawPixmap(m[i][1],100,p[i]);} pip.end();}void Window::keyPressEvent(QKeyEvent* e){ if(e->key()==Qt::Key_Return) exit(0); if(e->key()==Qt::Key_Space) {yes=true; update(); }}
int main(int argc, char** argv){.....QApplication app(argc, argv); Window win;QPixmap pix("img/screen.png");QPixmap p[30];////Объявляю после виджета win;...}
QPixmap p[30]; ////Объявляю до виджета win и main();int main(int argc, char** argv){.... QApplication app(argc, argv); Window win; QPixmap pix("img/screen.png");.....}
#include <qapplication.h>#include<qpixmap.h>#include <qlabel.h>#include <QMouseEvent>#include<qbitmap>#include <qpainter.h>bool yes=false;QPixmap *p[7]; class Window : public QLabel {private: QPoint m_ptPosition;protected: virtual void Window::mousePressEvent(QMouseEvent* pe) { m_ptPosition = pe->pos(); } virtual void Window::mouseMoveEvent(QMouseEvent* pe) { move(pe->globalPos() - m_ptPosition); } virtual void keyPressEvent(QKeyEvent* e);public: Window(QWidget* pwgt = 0) : QLabel(pwgt,Qt::FramelessWindowHint | Qt::Window) { }void paintEvent( QPaintEvent * );};void Window::paintEvent( QPaintEvent * ){ QPainter pip; pip.begin(this); pip.drawPixmap(0,0,QPixmap("img/screen.png")); pip.setBrush(QBrush(Qt::red,Qt::DiagCrossPattern)); pip.setPen(QPen(Qt::blue,3,Qt::DashLine)); pip.drawRect((QRect(10,10,30,30))); if(yes){ pip.drawPixmap(0,0,QPixmap("img/1.png"));} pip.end();}void Window::keyPressEvent(QKeyEvent* e){ if(e->key()==Qt::Key_Return) exit(0); if(e->key()==Qt::Key_Space) {yes=true; update(); }}// ----------------------------------------------------------------------int main(int argc, char** argv){ QApplication app(argc, argv); Window win; QPixmap pix("img/screen.png");qint32 m[30][30];int t=40;for(int y=1;y<=7;y++){m[y][1]=t;t+=50;} p[1]->load("img/1.png"); p[2]->load("img/2.png"); p[3]->load("img/3.png"); p[4]->load("img/4.png"); p[5]->load("img/5.png"); p[6]->load("img/6.png"); p[7]->load("img/7.png"); win.setPixmap(pix); win.setMask(pix.mask()); win.show(); return app.exec();}
C++ (Qt) QPixmap *p[ 7 ]; int main(...){ QApplication app(...); for( int i = 0; i < 7; ++i ) p[ i ] = new QPixmap( name[ i ] ); // Создаем объект QPixmap}