zoukankan      html  css  js  c++  java
  • QDialog弹出一个窗口,改变窗口大小

    创建一个QT应用

    文件->新建文件或项目

    Application->Qt Widgets Application

    其他下一步

    image

    基类选择QDialog

    其他下一步

    image

    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 }
  • 相关阅读:
    FileWriter写数据路径问题及关闭和刷新方法的区别
    FileWriter剖析
    2018-10-27 22:44:33 c language
    2018-10-23 23:29:54 clanguage
    Just write about
    2018-10-19 00:13:35 ArrayList
    2018-10-18 22:15:32 c language
    Why do collection classes appear
    2018-10-17 22:20:39 c language
    2018-10-16 22:56:13 c language
  • 原文地址:https://www.cnblogs.com/denggelin/p/5617494.html
Copyright © 2011-2022 走看看