Qt入门教程详细讲解版

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

QtC++QtQtQtC++1Qt2QtC++12QtQtQtdemo$QTDIR/examples/demoQtQtAPIAPIQtQtQtHelloWorldQtQt1.Hello,World!2.3.4.5.6.7.8.9.10.11.12.13.14.QtHello,World!HelloWorldQt/********************************************************************Qt-2******************************************************************/#includeqapplication.h#includeqpushbutton.hintmain(intargc,char**argv){QApplicationa(argc,argv);QPushButtonhello(Helloworld!,0);hello.resize(100,30);a.setMainWidget(&hello);hello.show();returna.exec();}#includeqapplication.hQApplicationQtQApplicationQApplication#includeqpushbutton.hQPushButtonQPushButtonQWidgetQPushButtonQPixmapintmain(intargc,char**argv){main()Qtmain()QtQtargcargvC/C++QtQtQApplicationa(argc,argv);aQApplicationX-displayQtargvargcQApplication::argv()QtQApplicationQPushButtonhello(Helloworld!,0);QApplicationHelloworld!0hello.resize(100,30);10030a.setMainWidget(&hello);hello.show();show()returna.exec();main()Qtexec()exec()Qt}C++makefileQtmakefileQtqmakemain.cppqmake-projectqmakeqmake.promakefilemakenmakeVisualStudioQtHellowWorld!X-geometry-geometry100x200+10+20[][]Qt/********************************************************************Qt-2******************************************************************/#includeqapplication.h#includeqpushbutton.h#includeqfont.hintmain(intargc,char**argv){QApplicationa(argc,argv);QPushButtonquit(Quit,0);quit.resize(75,30);quit.setFont(QFont(Times,18,QFont::Bold));QObject::connect(&quit,SIGNAL(clicked()),&a,SLOT(quit()));a.setMainWidget(&quit);quit.show();returna.exec();}#includeqfont.hQFontqfont.hQtXQPushButtonquit(Quit,0);Quit0quit.resize(75,30);Helloworld!QFontMetricsquit.setFont(QFont(Times,18,QFont::Bold));Times18QApplication::setFont()QObject::connect(&quit,SIGNAL(clicked()),&a,SLOT(quit()));connectQtconnect()QObjectsocketconnect()QtQObjectQtsignalsslotsQtQWidgetQWidgetQObjectquitclicked()aquit()makefileconnect()QPushButtonquitQPushButtonQButtonQt/********************************************************************Qt-3******************************************************************/#includeqapplication.h#includeqpushbutton.h#includeqfont.h#includeqvbox.hintmain(intargc,char**argv){QApplicationa(argc,argv);QVBoxbox;box.resize(200,120);QPushButtonquit(Quit,&box);quit.setFont(QFont(Times,18,QFont::Bold));QObject::connect(&quit,SIGNAL(clicked()),&a,SLOT(quit()));a.setMainWidget(&box);box.show();returna.exec();}#includeqvbox.hqvbox.hQVBoxbox;QVBoxQWidget::sizePolicy()box.resize(200,120);120200QPushButtonquit(Quit,&box);QPushButtontextboxQVBoxbox.show();QWidget::hide()QWidget::sizeHint()QWidget::setSizePolicy()makefileQt/********************************************************************Qt-4******************************************************************/#includeqapplication.h#includeqpushbutton.h#includeqfont.hclassMyWidget:publicQWidget{public:MyWidget(QWidget*parent=0,constchar*name=0);};MyWidget::MyWidget(QWidget*parent,constchar*name):QWidget(parent,name){setMinimumSize(200,120);setMaximumSize(200,120);QPushButton*quit=newQPushButton(Quit,this,quit);quit-setGeometry(62,40,75,30);quit-setFont(QFont(Times,18,QFont::Bold));connect(quit,SIGNAL(clicked()),qApp,SLOT(quit()));}intmain(intargc,char**argv){QApplicationa(argc,argv);MyWidgetw;w.setGeometry(100,100,200,120);a.setMainWidget(&w);w.show();returna.exec();}classMyWidget:publicQWidget{public:MyWidget(QWidget*parent=0,constchar*name=0);};QWidgetQWidgetQtMyWidget::MyWidget(QWidget*parent,constchar*name):QWidget(parent,name)parentnameQWidget{setMinimumSize(200,120);setMaximumSize(200,120);QPushButton*quit=newQPushButton(Quit,this,quit);quit-setGeometry(62,40,75,30);quit-setFont(QFont(Times,18,QFont::Bold));quitthisquitMyWidgetQtMyWidgetMyWidgetQtsetGeometry()move()resize()connect(quit,SIGNAL(clicked()),qApp,SLOT(quit()));}MyWidgetQtqAppMyWidgetQtqAppintmain(intargc,char**argv){QApplicationa(argc,argv);MyWidgetw;w.setGeometry(100,100,200,120);a.setMainWidget(&w);w.show();returna.exec();}makefilemain()MyWidgetQPushButton|||Qt/********************************************************************Qt-5******************************************************************/#includeqapplication.h#includeqpushbutton.h#includeqslider.h#includeqlcdnumber.h#includeqfont.h#includeqvbox.hclassMyWidget:publicQVBox{public:MyWidget(QWidget*parent=0,constchar*name=0);};MyWidget::MyWidget(QWidget*parent,constchar*name):QVBox(parent,name){QPushButton*quit=newQPushButton(Quit,this,quit);quit-setFont(QFont(Times,18,QFont::Bold));connect(quit,SIGNAL(clicked()),qApp,SLOT(quit()));QLCDNumber*lcd=newQLCDNumber(2,this,lcd);QSlider*slider=newQSlider(Horizontal,this,slider);slider-setRange(0,99);slider-setValue(0);connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));}intmain(intargc,char**argv){QApplicationa(argc,argv);MyWidgetw;a.setMainWidget(&w);w.show();returna.exec();}#includeqapplication.h#includeqpushbutton.h#includeqslider.h#includeqlcdnumber.h#includeqfont.h#includeqvb

1 / 91
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功