i created scroll area using designer and adding line edit in run time, when button clicked….
But scroll area is not expanding(scroll bars are inactive even though i set scrollbarAlways on)
please help me…
here is my complete code..

mainwindow.h

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class MainWindow;
  8. }
  9.  
  10. class MainWindow : public QMainWindow
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit MainWindow(QWidget *parent = 0);
  16. ~MainWindow();
  17.  
  18. private slots:
  19. void on_pushButton_clicked();
  20.  
  21. private:
  22. Ui::MainWindow *ui;
  23. };
  24.  
  25. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 


mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9.  
  10.  
  11.  
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16. delete ui;
  17. }
  18.  
  19.  
  20.  
  21. void MainWindow::on_pushButton_clicked()
  22. {
  23.  
  24. ui->gridLayout->addWidget(le);
  25.  
  26.  
  27. ui->scrollArea->setWidgetResizable(true);
  28.  
  29. }
To copy to clipboard, switch view to plain text mode 


mainwindow.ui

Qt Code:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>MainWindow</class>
  4. <widget class="QMainWindow" name="MainWindow">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>400</width>
  10. <height>300</height>
  11. </rect>
  12. </property>
  13. <property name="windowTitle">
  14. <string>MainWindow</string>
  15. </property>
  16. <widget class="QWidget" name="centralWidget">
  17. <layout class="QVBoxLayout" name="verticalLayout">
  18. <property name="sizeConstraint">
  19. <enum>QLayout::SetMinAndMaxSize</enum>
  20. </property>
  21. <item>
  22. <widget class="QScrollArea" name="scrollArea">
  23. <property name="widgetResizable">
  24. <bool>true</bool>
  25. </property>
  26. <widget class="QWidget" name="scrollAreaWidgetContents">
  27. <property name="geometry">
  28. <rect>
  29. <x>0</x>
  30. <y>0</y>
  31. <width>380</width>
  32. <height>198</height>
  33. </rect>
  34. </property>
  35. <widget class="QWidget" name="">
  36. <property name="geometry">
  37. <rect>
  38. <x>40</x>
  39. <y>31</y>
  40. <width>216</width>
  41. <height>25</height>
  42. </rect>
  43. </property>
  44. <layout class="QGridLayout" name="gridLayout">
  45. <property name="sizeConstraint">
  46. <enum>QLayout::SetMinAndMaxSize</enum>
  47. </property>
  48. <item row="0" column="0">
  49. <widget class="QPushButton" name="pushButton_2">
  50. <property name="text">
  51. <string>PushButton</string>
  52. </property>
  53. </widget>
  54. </item>
  55. <item row="0" column="1">
  56. <widget class="QLineEdit" name="lineEdit"/>
  57. </item>
  58. </layout>
  59. </widget>
  60. </widget>
  61. </widget>
  62. </item>
  63. <item>
  64. <widget class="QPushButton" name="pushButton">
  65. <property name="text">
  66. <string>PushButton</string>
  67. </property>
  68. </widget>
  69. </item>
  70. </layout>
  71. </widget>
  72. <widget class="QMenuBar" name="menuBar">
  73. <property name="geometry">
  74. <rect>
  75. <x>0</x>
  76. <y>0</y>
  77. <width>400</width>
  78. <height>21</height>
  79. </rect>
  80. </property>
  81. </widget>
  82. <widget class="QToolBar" name="mainToolBar">
  83. <attribute name="toolBarArea">
  84. <enum>TopToolBarArea</enum>
  85. </attribute>
  86. <attribute name="toolBarBreak">
  87. <bool>false</bool>
  88. </attribute>
  89. </widget>
  90. <widget class="QStatusBar" name="statusBar"/>
  91. </widget>
  92. <layoutdefault spacing="6" margin="11"/>
  93. <resources/>
  94. <connections/>
  95. </ui>
To copy to clipboard, switch view to plain text mode