×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Scroll bars in scroll area not comming in scroll area

    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
    Code:
       #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

    Code:
        #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
    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>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>

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2009
    Posts
    1,024

    Re: Scroll bars in scroll area not comming in scroll area

    Hi,
    code looks okay to me. Gridview is the layout of the scrollbar central widget and that's okay.
    You don't see the bars because the central widget has the same size of the scrollarea in runtime.
    The bars are shown when the central widget becomes bigger u size than the scrollarea.
    You could try this just setting a minimum size (0x0 by default) to the central widget using designer.

Similar Threads

  1. Replies: 5
    Last Post: 2011-02-03, 14:07
  2. Qt Designer and scroll area
    By bobford in forum [Archived] Qt SDKs and Tools
    Replies: 4
    Last Post: 2011-01-16, 04:33
  3. How to make a scroll area work?
    By nuthon in forum Qt
    Replies: 1
    Last Post: 2010-10-06, 08:20
  4. Scroll bars
    By fonedev12 in forum Symbian
    Replies: 1
    Last Post: 2001-11-08, 17:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •