QWidget control
Solved
General and Desktop
-
-
My new updated code:
Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); b1 = new QPushButton("Hello", this); b1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); b1->resize(this->size()); b1->show(); } Widget::~Widget() { delete ui; } void Widget::resizeEvent(QResizeEvent *event) { // qDebug() << event->oldSize(); b1->resize(event->size()); QWidget::resizeEvent(event); }
-
@JonB
hi,i had used this code in QWidget Constructor as given below:
Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); b1 = new QPushButton("Hello", this); b1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); b1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); b1->resize(this->size()); b1->show(); } I now found a solution for my requirement: i had used override function of resizeEvent of QWidget and it worked:
void Widget::resizeEvent(QResizeEvent *event)
{
// qDebug() << event->oldSize();
b1->resize(event->size());
QWidget::resizeEvent(event);
}Thank you for being with me.:)
-
My new updated code:
Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); b1 = new QPushButton("Hello", this); b1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); b1->resize(this->size()); b1->show(); } Widget::~Widget() { delete ui; } void Widget::resizeEvent(QResizeEvent *event) { // qDebug() << event->oldSize(); b1->resize(event->size()); QWidget::resizeEvent(event); }
-
-
@dan1973 said in QWidget control:
b1->resize(this->size());
I wouldn't even bother doing this in the constructor --- did you
qDebug() << this->size()
there like I suggested? But up to you, I guess it does no harm, it will get overwritten by call toWidget::resizeEvent()
as soon as shown, I think.