Widget's geometry before first show
-
bq. or to any other custom size?
What is the custom size?
I do not know PROPER (correct) size. PROPER size = size of widget, when it fits its parent widget (Stack in the example)Of course, I can calculate (how it does Qt layout system) it by myself, but then I must write half of Qt layout system), to take into account indents, different platforms and so on...
-
you are right, calculating the sizes though possible will be a tall order. In your case, you want to animate only on click of a button, at which points I assume all the widgets will be created, laid out in the layout, so will be sized properly.
That corresponds to the following in your test code ...
@
void MainWindow::on_Timer_timeout()
{
qDebug() << "MainWindow::on_Timer_timeout(): Geometry of second button before animation" << Stack->currentWidget()->geometry();// At this point all widgets are laid out and sized properly, but the widget is still not shown // You can set the initial size and target size. Stack->setCurrentIndex(1); // widget is shown now with initial size... and you can animate at this point? qDebug() << "MainWindow::on_Timer_timeout(): Geometry of second button after show" << Stack->currentWidget()->geometry();
}
@ -
bq. you want to animate only on click of a button,
Yes
bq. at which points I assume all the widgets will be created,
Yes
bq. laid out in the layout,
Yes
bq. so will be sized properly.
No... They all added to QStackedLayout, but not shown. Only one (first of them) shown when app has started. And only after they all are shown though one time, they will have proper size. But at start, only on of them is shown...
Since they all has the same size, I think, I can use proper size of this first shown widget.
-
QStackedWidget provides a stack of widgets where only one widget is visible at a time.
So i think the geometry of all widget if is not specific, it will be the geometry of the QStackedWidget.size of
@
QStackedWidget->widget(0)->geometry();
QStackedWidget->widget(1)->geometry(); @after use
@
QStackedWidget->setCurrentIndex(number);@is
@
QStackedWidget->geometry();@But i not understand if this is useful for you or not :)
-
Did you try after creating widget call QWidget::adjustSize()? as recommended here:
http://stackoverflow.com/questions/4963220/qt-how-to-preview-sizes-of-widgets-in-layout-before-a-show -
You're right, I saw that ))), but as I understood DimanNe did find good solution. I've come across the same problem and QWidget::adjustSize() works well and looks better as for me. I posted that just for the case if someone like me has the same problem and check QWidget::adjustSize().