I need to get the height and width for a QFrame inside a tab of a QTabWidget. The QFrame is inside the first tab of the tabwidget and I can only get the right width and height if this is the tab selected when I do showMaximized. From what I understand I can get the width and height if the widget have been shown as this is when it is calculated. So from what I understand the best way to get the size must be when changing between the tabs and the new tab is visible. How can I do that?

Its a little bit hard to explain the problem but the main thing is that I need to get the height and width of a QFrame and as the QFrame is depending of the screen size it changes when it becomes visible. So how can I get the size of the QFrame?

This is the code (If I set tabWidget->setCurrentIndex(0) I get the right size in whatIsTheSize(), as 0 is the tabindex with the QFrame inside.)
main.cpp:
Qt Code:
  1. TestSize *w = new TestSize();
  2. w->showMaximized();
  3. w->whatIsTheSize();
To copy to clipboard, switch view to plain text mode 

TestSize.cpp:
Qt Code:
  1. void TestSize::whatIsTheSize() {
  2. int WIDGETWIDTH = ui.frame->width();
  3. int WIDGETHEIGHT = ui.frame->height();
  4. }
To copy to clipboard, switch view to plain text mode 

ui_testsize.h:
Qt Code:
  1. void setupUi(QWidget *TestSizeClass)
  2. {
  3. if (TestSizeClass->objectName().isEmpty())
  4. TestSizeClass->setObjectName(QString::fromUtf8("TestSizeClass"));
  5. TestSizeClass->resize(207, 300);
  6. verticalLayout = new QVBoxLayout(TestSizeClass);
  7. verticalLayout->setSpacing(6);
  8. verticalLayout->setContentsMargins(11, 11, 11, 11);
  9. verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
  10. tabWidget = new QTabWidget(TestSizeClass);
  11. tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
  12. tab_3 = new QWidget();
  13. tab_3->setObjectName(QString::fromUtf8("tab_3"));
  14. verticalLayout_2 = new QVBoxLayout(tab_3);
  15. verticalLayout_2->setSpacing(6);
  16. verticalLayout_2->setContentsMargins(11, 11, 11, 11);
  17. verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
  18. frame = new QFrame(tab_3);
  19. frame->setObjectName(QString::fromUtf8("frame"));
  20. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  21. sizePolicy.setHorizontalStretch(0);
  22. sizePolicy.setVerticalStretch(0);
  23. sizePolicy.setHeightForWidth(frame->sizePolicy().hasHeightForWidth());
  24. frame->setSizePolicy(sizePolicy);
  25. frame->setFrameShape(QFrame::StyledPanel);
  26. frame->setFrameShadow(QFrame::Raised);
  27.  
  28. verticalLayout_2->addWidget(frame);
  29.  
  30. tabWidget->addTab(tab_3, QString());
  31. tab_4 = new QWidget();
  32. tab_4->setObjectName(QString::fromUtf8("tab_4"));
  33. verticalLayout_3 = new QVBoxLayout(tab_4);
  34. verticalLayout_3->setSpacing(6);
  35. verticalLayout_3->setContentsMargins(11, 11, 11, 11);
  36. verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
  37. frame_2 = new QFrame(tab_4);
  38. frame_2->setObjectName(QString::fromUtf8("frame_2"));
  39. frame_2->setFrameShape(QFrame::StyledPanel);
  40. frame_2->setFrameShadow(QFrame::Raised);
  41.  
  42. verticalLayout_3->addWidget(frame_2);
  43.  
  44. tabWidget->addTab(tab_4, QString());
  45.  
  46. verticalLayout->addWidget(tabWidget);
  47.  
  48. retranslateUi(TestSizeClass);
  49.  
  50. tabWidget->setCurrentIndex(1);
  51.  
  52. QMetaObject::connectSlotsByName(TestSizeClass);
  53. }
To copy to clipboard, switch view to plain text mode 

Thanks really much!