(C++) How to resize a dialog?
February 24, 2017 · View on GitHub
(C++)
How to resize a dialog?
There are multiple options:
- this->resize(int any_width,int any_height)
- this->setGeometry(int any_left, int any_right, int any_width,int any_height)
- 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.