Results 1 to 2 of 2

Thread: Layout issue

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Layout issue

    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.

    Qt Code:
    1. void H3DNodePropertiesWidget::instantiateWidgets()
    2. {
    3. setUpdatesEnabled(false);
    4.  
    5. if(m_widgetState == NONE)
    6. {
    7. m_propertyWidget = new QWidget;
    8.  
    9. QGridLayout *gridLayout = new QGridLayout(m_propertyWidget);
    10. gridLayout->setContentsMargins(3,4,0,2);
    11. gridLayout->setSpacing(2);
    12. gridLayout->setColumnStretch(1,2);
    13.  
    14.  
    15. m_mainLayout->addWidget(m_propertyWidget);
    16.  
    17. setUpdatesEnabled(true);
    18. updateState();
    19. m_widgetFactory = 0;
    20.  
    21. m_widgetState = ONLY_TF;
    22.  
    23. }
    24. //THIS FOLLOWING CONDITION IS THE RESPOONSIBLE FOR CREATING ALL THE WIDGETS
    25. // THAT CORRESPONDS TO THE ELLIPTICAL ITEM YOU SEE IN THE SCENE
    26. else if(m_widgetState == ONLY_TF)
    27. {
    28. //!pull out the layout that has been created when the
    29. //!widget instantiation state was = NONE
    30. QGridLayout *gridLayout = dynamic_cast<QGridLayout*>(m_propertyWidget->layout());
    31.  
    32. //!now get the properties of the nodes
    33. QList<H3DProperty*> propertyList = m_h3dNode->getH3DNodeProperties();
    34.  
    35.  
    36. //!create the widget for every property and put them in the vertical layout
    37. int rows = 0;
    38.  
    39.  
    40. /////////////////////////////////////////////////////////////////
    41. //!The DEF label and the line edit is common to every elliptical graphical item
    42. //!add the DEF node editing capabilities here
    43. QLabel *nodeDEFname = new QLabel(tr("DEF"));
    44.  
    45. QLineEdit *nodeDEFNameEdit = new QLineEdit(m_h3dNode->getNodeDEFName());
    46.  
    47. //resize the widget
    48. // nodeDEFNameEdit->resize(QSize(156,86).expandedTo(minimumSizeHint()));
    49.  
    50. QSizePolicy sizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
    51. sizePolicy.setHorizontalStretch(0);
    52. sizePolicy.setVerticalStretch(0);
    53.  
    54. sizePolicy.setHeightForWidth(nodeDEFname->sizePolicy().hasHeightForWidth());
    55.  
    56. nodeDEFname->setSizePolicy(sizePolicy);
    57.  
    58.  
    59. QHBoxLayout *horizontalLayout = new QHBoxLayout();
    60.  
    61. horizontalLayout->addWidget(nodeDEFname);
    62. horizontalLayout->addWidget(nodeDEFNameEdit);
    63.  
    64. gridLayout->addLayout(horizontalLayout,rows,0,1,1);
    65.  
    66.  
    67. rows++;
    68. /////////////////////////////////////////////////////////////////
    69.  
    70. //check first if the pointer is the valid one or not
    71. if(!m_widgetFactory)
    72. {
    73. if(!Singleton<H3DPropertyWidgetFactory>::isInited())
    74. {
    75. Singleton<H3DPropertyWidgetFactory>::init(new H3DPropertyWidgetFactory());
    76.  
    77. }
    78.  
    79. m_widgetFactory = Singleton<H3DPropertyWidgetFactory>::getPtr();
    80. }
    81.  
    82. //declare an iterator to browse through the property lists
    83. QList<H3DProperty*>::iterator iter;
    84.  
    85. for(iter = propertyList.begin(); iter != propertyList.end();++iter)
    86. {
    87.  
    88. H3DPropertyWidget *l_propertyWidget = dynamic_cast<H3DPropertyWidget*>((*iter)->createAndAddWidget(m_widgetFactory));
    89.  
    90. if(l_propertyWidget != 0)
    91. {
    92. m_widgets.push_back(l_propertyWidget);
    93.  
    94. connect(l_propertyWidget,SIGNAL(modified()),this,SLOT(propertyModified()));
    95.  
    96. QLabel *l_nameLabel = const_cast<QLabel*>(l_propertyWidget->getNameLabel());
    97.  
    98. if(l_nameLabel)
    99. {
    100. gridLayout->addWidget(l_nameLabel,rows,0,1,1);
    101. gridLayout->addWidget(l_propertyWidget,rows,1,1,1);
    102. }
    103. // else
    104. // {
    105. // gridLayout->addWidget(l_propertyWidget,rows,0,1,2);
    106. // }
    107. }
    108.  
    109.  
    110. //!just increment the row value
    111. ++rows;
    112. }
    113.  
    114. m_widgetFactory = 0;
    115. setUpdatesEnabled(true);
    116. updateState();
    117.  
    118. m_widgetState = ALL;
    119.  
    120.  
    121. }
    122.  
    123. setUpdatesEnabled(true);
    124. }
    To copy to clipboard, switch view to plain text mode 


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


    Regards
    Sajjad

  2. #2
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Layout issue

    Sorry forum ,


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


    Here it goes.Screenshot-1.jpg

Similar Threads

  1. QT layout issue
    By meraj ansari in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2010, 23:33
  2. Issue with layout
    By N3wb in forum Newbie
    Replies: 2
    Last Post: 22nd September 2009, 17:01
  3. customized layout issue
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2008, 07:02
  4. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  5. Qt layout issue
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 15th August 2007, 19:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.