Search code examples
c++qtqpushbuttonqdialog

How to change the width of a QDialog box with the help of Qpushbutton


i have a QDialog box named "Validate dialog" and a QPushbutton on that dialog named "Refresh Width" , when i click this button the width of the QDialog box must be changed from 1000 to 500,

by reading some documentation , i got to know that i can probably use setFixedWidth(int w) function , and tried using it but facing some syntax issues.

but i can use that for QPushbutton and other widgets on the QDialog, but how to use setFixedWidth to change the width of main QDialog upon clicking the pushbutton ??


Solution

  • @Mr_Workalot It's quite basic so in the first time I think it's not necessary to show the source. But to avoid the confusion or misunderstanding, below is the code for your reference.

    #include "dialog.h"
    #include "ui_dialog.h"
    
    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
        resize(1000, 400);
    }
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    void Dialog::on_pushButton_clicked()
    {
        setFixedWidth(500);
    }