PDA

View Full Version : Layout issue



sajis997
6th December 2011, 10:03
Hello forum,

I am instantiating property widgets and arranging them in a layout with the click event dynamically.

I hope that the attached screen-shot gives you the idea. As you can see that the layout is not working
properly. The label "DEF" and the line edit arrangement is not aligning well with rest of the other properties.

I am also attaching the corresponding code snippet so that you can provide me some useful hint to get around
this issue.




void H3DNodePropertiesWidget::instantiateWidgets()
{
setUpdatesEnabled(false);

if(m_widgetState == NONE)
{
m_propertyWidget = new QWidget;

QGridLayout *gridLayout = new QGridLayout(m_propertyWidget);
gridLayout->setContentsMargins(3,4,0,2);
gridLayout->setSpacing(2);
gridLayout->setColumnStretch(1,2);


m_mainLayout->addWidget(m_propertyWidget);

setUpdatesEnabled(true);
updateState();
m_widgetFactory = 0;

m_widgetState = ONLY_TF;

}
//THIS FOLLOWING CONDITION IS THE RESPOONSIBLE FOR CREATING ALL THE WIDGETS
// THAT CORRESPONDS TO THE ELLIPTICAL ITEM YOU SEE IN THE SCENE
else if(m_widgetState == ONLY_TF)
{
//!pull out the layout that has been created when the
//!widget instantiation state was = NONE
QGridLayout *gridLayout = dynamic_cast<QGridLayout*>(m_propertyWidget->layout());

//!now get the properties of the nodes
QList<H3DProperty*> propertyList = m_h3dNode->getH3DNodeProperties();


//!create the widget for every property and put them in the vertical layout
int rows = 0;


/////////////////////////////////////////////////////////////////
//!The DEF label and the line edit is common to every elliptical graphical item
//!add the DEF node editing capabilities here
QLabel *nodeDEFname = new QLabel(tr("DEF"));

QLineEdit *nodeDEFNameEdit = new QLineEdit(m_h3dNode->getNodeDEFName());

//resize the widget
// nodeDEFNameEdit->resize(QSize(156,86).expandedTo(minimumSizeHint()) );

QSizePolicy sizePolicy(QSizePolicy::Preferred,QSizePolicy::Fix ed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);

sizePolicy.setHeightForWidth(nodeDEFname->sizePolicy().hasHeightForWidth());

nodeDEFname->setSizePolicy(sizePolicy);


QHBoxLayout *horizontalLayout = new QHBoxLayout();

horizontalLayout->addWidget(nodeDEFname);
horizontalLayout->addWidget(nodeDEFNameEdit);

gridLayout->addLayout(horizontalLayout,rows,0,1,1);


rows++;
/////////////////////////////////////////////////////////////////

//check first if the pointer is the valid one or not
if(!m_widgetFactory)
{
if(!Singleton<H3DPropertyWidgetFactory>::isInited())
{
Singleton<H3DPropertyWidgetFactory>::init(new H3DPropertyWidgetFactory());

}

m_widgetFactory = Singleton<H3DPropertyWidgetFactory>::getPtr();
}

//declare an iterator to browse through the property lists
QList<H3DProperty*>::iterator iter;

for(iter = propertyList.begin(); iter != propertyList.end();++iter)
{

H3DPropertyWidget *l_propertyWidget = dynamic_cast<H3DPropertyWidget*>((*iter)->createAndAddWidget(m_widgetFactory));

if(l_propertyWidget != 0)
{
m_widgets.push_back(l_propertyWidget);

connect(l_propertyWidget,SIGNAL(modified()),this,S LOT(propertyModified()));

QLabel *l_nameLabel = const_cast<QLabel*>(l_propertyWidget->getNameLabel());

if(l_nameLabel)
{
gridLayout->addWidget(l_nameLabel,rows,0,1,1);
gridLayout->addWidget(l_propertyWidget,rows,1,1,1);
}
// else
// {
// gridLayout->addWidget(l_propertyWidget,rows,0,1,2);
// }
}


//!just increment the row value
++rows;
}

m_widgetFactory = 0;
setUpdatesEnabled(true);
updateState();

m_widgetState = ALL;


}

setUpdatesEnabled(true);
}




It has been quite a while that i am stuck with this issue and i am really looking forward to some hint.


Regards
Sajjad

sajis997
6th December 2011, 15:42
Sorry forum ,


I realized that i did not even attach the screen-shot.


Here it goes.7151