PDA

View Full Version : Scroll bars in scroll area not comming in scroll area



aurora
3rd January 2012, 11:57
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


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_pushButton_clicked();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H



mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);



}

MainWindow::~MainWindow()
{
delete ui;
}



void MainWindow::on_pushButton_clicked()
{
QLineEdit *le=new QLineEdit;

ui->gridLayout->addWidget(le);


ui->scrollArea->setWidgetResizable(true);

}



mainwindow.ui



<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>198</height>
</rect>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>40</x>
<y>31</y>
<width>216</width>
<height>25</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

aurora
4th January 2012, 06:02
Please somebody look at this issue....

ChrisW67
4th January 2012, 06:42
Remove the grid layout. Set the scroll area layout to grid with the starting push button and edit widget in that grid. Set the scrollBarWidgetContents layoutSizeConstraint to setFixedSize. Add new widgets with ui->scrollBarWidgetContents->layout()->addWidget().

If you want the scroll bars visible at all times then you should set that... it isn't in your example.

aurora
4th January 2012, 06:50
THANK A LOT CHRIS....:)
now its working fine.....