Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Qt How to resize a dialog?

 

There are multiple options:

  1. this->resize(int any_width,int any_height)
  2. this->setGeometry(int any_left, int any_right, int any_width,int any_height)
  3. this->setGeometry(QRect any_rect)

Resize this in a member function of the dialog.

 

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
  ui->setupUi(this);
  //Resize the dialog to 100x100 pixels
  this->resize(100,100);
}

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

void Dialog::changeEvent(QEvent *e)
{
  QDialog::changeEvent(e);
  switch (e->type()) {
  case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
  default:
    break;
  }
}

void Dialog::resizeEvent(QResizeEvent*)
{
  static int n_times = 0;
  QString s; s = s.number(n_times);
  ui->label->setText("Resized " + s + " times");
  ++n_times;
}

 

Example 10 shows how to implement a resize event.

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict