[Qt-interest] Layout issue

Sajjad dosto.walla at gmail.com
Fri Nov 19 05:50:40 CET 2010


Hello Alex,

One of the attachments may not have been delivered. So i am pasting the code
here instead:


**********************************************************************************************

#include "DynamicWidget.h"

 DynamicWidget::DynamicWidget(QWidget *parent)

    :QWidget(parent)

{

    //setupUi(this);

     // i shall set up the gui by myself

     //create the main Layout

    m_mainLayout = new QVBoxLayout;

     //create the horizontal layout for

    //the label and the line edit

    m_horizontalLayout = new QHBoxLayout;

     //the layout that will be changing its contents

    m_dynamicLayout = new QGridLayout;

     m_nodeLabel = new QLabel("&Node Name:",this);

    m_lineEdit = new QLineEdit(this);

    m_nodeLabel->setBuddy(m_lineEdit);

     m_horizontalLayout->addWidget(m_nodeLabel);

    m_horizontalLayout->addWidget(m_lineEdit);

     m_mainLayout->addLayout(m_horizontalLayout);

    m_mainLayout->addLayout(m_dynamicLayout);

     setLayout(m_mainLayout);

     connect(m_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(adjustWidgets(const
QString&)));

}

 void DynamicWidget::adjustWidgets(const QString &strNum)

{

     int num = strNum.toInt();

     //first check if there is any existing layout

    //if it is there, then remove it from the list

    if(checkBoxLists.size() > 0)

    {

        for(int i = 0; i < checkBoxLists.size();i++)

        {

            m_dynamicLayout->removeWidget(checkBoxLists[i]);

         }

        qDeleteAll(checkBoxLists);

        checkBoxLists.clear();

    }

      if(num > 0)

    {

        for(int i = 0; i < num; i++)

        {

            for(int j = 0; j < 2; j++)

            {

                //int col = j + 1;

                if(j == 2)

                    break;

                else

                {

                    checkBoxLists.push_back(new QCheckBox(tr("Boolean
Value: %1").arg(i+1),this));

                    m_dynamicLayout->addWidget(checkBoxLists.back(),i,j);

                }

            }

        }

    }

}

 DynamicWidget::~DynamicWidget()

{

    qDeleteAll(checkBoxLists);

     checkBoxLists.clear();

}


**********************************************************************************************

On Fri, Nov 19, 2010 at 5:33 AM, Sajjad <dosto.walla at gmail.com> wrote:

> Hello Alex,
>
> I am getting the same scenario even after i detached the layout as
> suggested in the previous attachment you sent.
>
> I have the main layout as vbox layout.
>
> The label and the line edit in the horizontal layout.
>
>
> The checkboxes in the grid layout that are added dynamically with the
> keypress.
>
> Any other point of view on that?
>
>
> Regards
> Sajjad
>
>
>
> On Fri, Nov 19, 2010 at 2:20 AM, Malyushytsky, Alex <alex at wai.com> wrote:
>
>> If I assume correctly, you would like to have  label and edit control
>> being resize  independently from check boxes.
>> Putting them in the same layout makes their sizes dependent on each other.
>>
>> Solution is based on what you want to achieve.
>>
>> You can try to keep work mostly with only your widget grid layout.
>> In this case when you add/remove checkboxes you should also remove edit
>> control ( I would place them in the independent horizontal layout anyway)
>> And re-add it with add function which specifies 'rowSpan' according to the
>> current number of checkboxes.
>>
>> But I would suggest give each group of controls its own layout like on the
>> picture in the attachment.
>>
>> Make the widget layout vertical layout, group label and edit control with
>> horizontal layout,
>> Group all the checkboxes in the grid layout. (If you decide to create last
>> layout dynamically you might need to use invalidate on widget layout, or you
>> can just to correct layout margins )
>>
>> Hope this helps,
>>  Alex
>>
>>
>>
>>
>>
>> In this case you should not put them in the same layout.
>> Cause grid layout
>>
>> So I would suggest to change layout structure (see attachment):
>> You will have 3 layouts
>> 1.
>>
>>
>>
>> From: qt-interest-bounces at trolltech.com [mailto:
>> qt-interest-bounces at trolltech.com] On Behalf Of Malyushytsky, Alex
>> Sent: Thursday, November 18, 2010 2:02 PM
>> To: qt-interest at trolltech.com
>> Subject: Re: [Qt-interest] Layout issue
>>
>> Try to call invalidate() on layout after changes.
>>
>> Alex
>>
>> From: qt-interest-bounces at trolltech.com [mailto:
>> qt-interest-bounces at trolltech.com] On Behalf Of Sajjad
>> Sent: Thursday, November 18, 2010 12:22 PM
>> To: qt-interest at trolltech.com
>> Subject: [Qt-interest] Layout issue
>>
>> Hello forum,
>>
>>
>> I have a label and line edit which is horizontal layout and this layout is
>> in turn inside the grid layout.
>>
>> I have declared a private slot that responds to  text changed signal of
>> the line edit.
>>
>>
>> The slots adds check boxes dynamically to the grid layout. Grid layout is
>> the main layout of the class that i have sub-classed form QWidget.
>>
>>
>> When i press 4, two four check boxes added dynamically to  the layout.
>> Then again when i press 1 , previously added 4 check boxes are removed and
>> the new one
>> check box is added to the layout. But there is the extra space which was
>> allocated while adding 4 check boxes. Those spaces remains ?
>>
>>
>> Any hint to maintain the size of the widget dynamically while adding and
>> removing check boxes from the layout?
>>
>>
>>
>> Regards
>> Sajjad
>>
>>
>>
>> ---------------------------------------------------------------------------------------------------
>> Weidlinger Associates, Inc. made the following annotations.
>>
>> "This message and any attachments are solely for the intended recipient
>> and may contain confidential or privileged information. If you are not the
>> intended recipient, any disclosure, copying, use, or distribution of the
>> information included in this message and any attachments is prohibited. If
>> you have received this communication in error, please notify us by reply
>> e-mail and immediately and permanently delete this message and any
>> attachments. Thank you."
>>
>> "Please consider our environment before printing this email."
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101119/79cd2d89/attachment.html 


More information about the Qt-interest-old mailing list