Scroll bars in scroll area not coming
-
Hi all,
Using Qt designer i created a Scroll area, and in run, dynamically adding widgets inside it...
But unfortunately, widgets are added but scroll bar not coming...Because of this only few widgets are visible....I searched in forum, many r unresolved problems...
Please help me to sort out my problem@
void MainWindow::on_pushButton_clicked()
{
QLabel *label =new QLabel;
label->setText("hello");
ui->verticalLayout->addWidget(label,10);ui->scrollArea->widgetResizable();
}
@
i set scroll bar policy as always on -
If i recall correctly "this":http://developer.qt.nokia.com/doc/qt-4.8/qlayout.html#SizeConstraint-enum is what you need.
-
I guess you didn't add a layout in the QScrollArea?
Try adding the widgets to that layout at run time then.
-
i added code...plz hav a look...
i added layouts..... -
ya i read that,....and set it "MinAndMaxSize"
[quote author="p-himik" date="1324972866"]If i recall correctly "this":http://developer.qt.nokia.com/doc/qt-4.8/qlayout.html#SizeConstraint-enum is what you need.[/quote] -
Is verticalLayout inside your scrollarea?
This is how you can do it in Qt Designer:
Add a QScrollArea in your form
Add some labels inside it
Select those labels and add a vertical layout. Remember it's name and add other labels at runtime like you did.Of course the QScrollArea should be in a layout too, but don't use this one. I guess that is what you do.
-
Sorry Eddy, i tried as u told...its not working, displays same as before, scrolling not activated...:(
-
Can you give us your ui file to look at?
-
Ya sure Eddy.....below is my ui file code..
@
<?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>734</width>
<height>708</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>30</x>
<y>150</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>50</x>
<y>220</y>
<width>291</width>
<height>141</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>272</width>
<height>122</height>
</rect>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>24</width>
<height>34</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>label</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>label</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_2">
<property name="geometry">
<rect>
<x>510</x>
<y>250</y>
<width>61</width>
<height>41</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>734</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>
@