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

📄 event.cpp

📁 几个qt-linux的练习小程序
💻 CPP
字号:
#include <qwidget.h>#include <qpainter.h>#include <qpicture.h>#include <qlabel.h>#include <qstring.h>#include <qapplication.h>#include <math.h>#include <qevent.h>class MyMainWindow:public QWidget{public:  MyMainWindow(QWidget* parent=0);void ReSize(int x, int y);};void MyMainWindow::ReSize(int X, int Y){    resize(X, Y);}MyMainWindow::MyMainWindow(QWidget *parent):QWidget(parent){}class DrawWidget:public QWidget{public:   DrawWidget();   MyMainWindow *draw;protected:    void drawIt( QPainter * );    void drawIt1( QPainter *p , QString a );    void paintEvent( QPaintEvent * );    void keyPressEvent(QKeyEvent *event);private:    void drawFonts(QPainter *p);  void drawFonts1(QPainter *p, QString a);};DrawWidget::DrawWidget() : QWidget(){    draw = new MyMainWindow(this);        qDebug("--------");    draw->ReSize(750, 550);    draw->setBackgroundColor(red);    update();    resize(800, 600);}void DrawWidget::drawIt( QPainter *p ){    drawFonts(p);}void DrawWidget::drawFonts( QPainter *p ){    p->drawText(10,10,"Please press 'shift' or 'end', thinks");}//keyeventvoid DrawWidget::drawIt1( QPainter *p , QString a){    drawFonts1(p , a);}void DrawWidget::drawFonts1( QPainter *p, QString a){    p->drawText(100,100,a);}//void DrawWidget::paintEvent( QPaintEvent *){    QPainter paint( draw );    drawIt( &paint );}void DrawWidget::keyPressEvent(QKeyEvent *event){    draw->erase ();    QPainter paint( draw ); /*   int b = event->key();    QString a = b + "";    drawIt1( &paint , a);  */    QString a;    switch (event->key()){	case Key_Shift:    		a ="the key is shift";		break;	case Key_End:		a ="the key is end";		break;    }    drawIt1( &paint , a);    }int main(int argc,char** argv){  QApplication app(argc,argv);  DrawWidget w;    app.setMainWidget(&w);  w.show();  return app.exec();}

⌨️ 快捷键说明

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