QWidget :: height () of the widget just added to the layout

How to get the final height of the widget that was added to the layout, but because of this, it has not changed to the final size?

Basically I need to do this:

myGridLayout->addWidget ( somewidget, 0, 0, 1, 1 );

QPushButton *b = new QPushButton(somewidget);
b->setGeometry( somewidget->width() - 50,
                somewidget->height()/2 - 150,
                50, 300);

What I want to do is insert a button (50x300) in the middle of the right edge of the newly added widget, but for this I need to know the size of the widget, which I do not get correctly, because it did not change to the full size in the layout. Any ideas?

+3
source share
2 answers

If I understand you correctly, this should accomplish what you are trying to do without trying to catch the size at the right time. Add a layout to your "someidget" and add a button to it.

myGridLayout->addWidget(somewidget, 0, 0, 1, 1 );

QGridLayout *layout = new QGridLayout(somewidget);
QPushButton *button = new QPushButton();
button->setText("button");
button->setMaximumSize(50,300);
button->setMinimumSize(50,300);
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
layout->addWidget(button, 0, 0, Qt::AlignVCenter | Qt::AlignRight);
0
source

. , QLayout::activate(), QLayout::update(), .

+2

Source: https://habr.com/ru/post/1765909/


All Articles