Mr_Workalot
Mr_Workalot

Reputation: 37

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 ??

Upvotes: 0

Views: 50

Answers (1)

wthung
wthung

Reputation: 167

@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);
}

Upvotes: 1

Related Questions