創建一個QT應用
文件->新建文件或項目
Application->Qt Widgets Application
其他下一步
基類選擇QDialog
其他下一步
resize()
改變窗口大小
show()
彈出窗口
main.cpp
1 #include "dialog.h" 2 #include <QApplication> 3 #include <windows.h> 4 5 class bigsmall 6 { 7 Dialog *p;//指針 8 public: 9 void setp(Dialog *p) 10 { 11 this->p=p;//設置指針 12 } 13 void set(int x,int y) 14 { 15 this->p->resize(x,y);//改變窗口大小 16 } 17 void tobig()//增大窗口 18 { 19 for(int i=0;i<600;i++) 20 { 21 this->p->resize(i,i); 22 } 23 } 24 void tosmall()//縮小窗口 25 { 26 for(int i=600;i>=0;i--) 27 { 28 this->p->resize(i,i); 29 } 30 } 31 }; 32 33 int main(int argc, char *argv[]) 34 { 35 QApplication a(argc, argv); 36 37 Dialog mydialog1;//創建類,在棧上 38 Dialog mydialog2;//創建類,在棧上 39 40 //mydialog1.show();//彈出窗口 41 //mydialog2.show();//彈出窗口 42 43 Dialog *pd1,*pd2;//創建指針指向類,在堆上 44 pd1=new Dialog; 45 pd2=new Dialog; 46 47 //pd1->show();//彈出窗口,用箭頭 48 //pd2->show();//彈出窗口,用箭頭 49 50 pd1->resize(800,600);//改變窗口大小 51 pd2->resize(600,800);//改變窗口大小 52 53 (*pd1).show();//彈出窗口,用. 54 (*pd2).show();//彈出窗口,用. 55 56 bigsmall bigsmalla;//創建類 57 bigsmalla.setp(pd1);//設置指針 58 bigsmalla.tobig();//增大窗口 59 bigsmalla.tosmall();//縮小窗口 60 61 bigsmall bigsmallb;//創建類 62 bigsmallb.setp(pd2);//設置指針 63 bigsmallb.tobig();//增大窗口 64 bigsmallb.tosmall();//縮小窗口 65 66 return a.exec(); 67 }
dialog.cpp
1 #include "dialog.h" 2 #include "ui_dialog.h" 3 4 Dialog::Dialog(QWidget *parent) : 5 QDialog(parent), 6 ui(new Ui::Dialog) 7 { 8 ui->setupUi(this); 9 } 10 11 Dialog::~Dialog() 12 { 13 delete ui; 14 }