Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User aurora26's Avatar
    Join Date
    Nov 2011
    Posts
    12
    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 gnuton's Avatar
    Join Date
    Mar 2009
    Posts
    1,024
    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 C++
    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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved