qt显示隐藏控件,窗口大小随之变化

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    main_window=this->geometry().width();   //获取当前窗口的宽度
    widget_window=ui->widget->geometry().width();   //获取widget的宽度
    this->setFixedWidth(main_window-widget_window); //设置窗口的宽度
    isshoweidget=false ;
    ui->widget->hide();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    if (isshoweidget==false)
    {

        ui->widget->show();
        ui->pushButton->setText("<<");
        this->setFixedWidth(main_window);
        isshoweidget=true;
    }
    else
    {
        ui->widget->hide();
        ui->pushButton->setText(">>");
        this->setFixedWidth(main_window-widget_window);
        isshoweidget=false;
    }

}

ui界面
qt显示隐藏控件,窗口大小随之变化_第1张图片

你可能感兴趣的:(Qt)