Results 1 to 6 of 6

Thread: QWidget Shyness Syndrome

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QWidget Shyness Syndrome

    I have made a widget with the following
    Qt Code:
    1. FrameInfo::FrameInfo(QWidget* parent )
    2. :QGroupBox(parent)
    3. {
    4. //ctor
    5.  
    6. QVBoxLayout *topLayout = new QVBoxLayout(this);
    7. QScrollArea* scrollArea = new QScrollArea(this);
    8. topLayout->addWidget(scrollArea);
    9. setLayout(topLayout);
    10.  
    11. //Now, for the group box
    12. holder = new QWidget(scrollArea);
    13. mainLayout = new QVBoxLayout(holder);
    14. holder->setLayout(mainLayout);
    15. mainLayout->addStretch();
    16.  
    17. scrollArea->setWidget(holder);
    18. }
    To copy to clipboard, switch view to plain text mode 

    and a function like this

    Qt Code:
    1. void FrameInfo::addInfo (QString infoName, QString val)
    2. {
    3. QHBoxLayout* infoLayout = new QHBoxLayout;
    4.  
    5. QLabel* lblValue = new QLabel (infoName,holder);
    6. infoLayout->addWidget(lblValue);
    7.  
    8.  
    9. QLineEdit* leValue = new QLineEdit (val,holder);
    10. leValue->setReadOnly ( true );
    11. leValue->setAlignment(Qt::AlignRight);
    12. infoLayout->addWidget(leValue);
    13.  
    14.  
    15. infoLayout->addStretch();
    16. mainLayout->insertLayout(mainLayout->count()-1,infoLayout);
    17.  
    18. holder->adjustSize();
    19. }
    To copy to clipboard, switch view to plain text mode 

    the symptom is that when this widget is not hidden and i will call addInfo I won't see my QLabel and QLineEdit anywhere, but if this widget is hidden ( not the current tab for the tabwidget) then call addInfo, when i let it show (by clicking the tab making this widget the current tab widget index ) then ill see them happy and breathing.

    please help my widget ease with this sickness,

    baray98

  2. #2
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget Shyness Syndrome

    one more symptoms if i remove this line

    Qt Code:
    1. holder->adjustSize(); //found in addInfo
    To copy to clipboard, switch view to plain text mode 

    it has the same effect i will see a blank groupBox. I think it has something to do with repainting my holder widget. what do you think guys?

    baray98

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget Shyness Syndrome

    Here you go(untested)
    Qt Code:
    1. void FrameInfo::addInfo (QString infoName, QString val)
    2. {
    3. QWidget *w = new QWidget(holder);
    4. QHBoxLayout* infoLayout = new QHBoxLayout(w);
    5. QLabel* lblValue = new QLabel (infoName,w);
    6. infoLayout->addWidget(lblValue);
    7. QLineEdit* leValue = new QLineEdit (val,w);
    8. leValue->setReadOnly ( true );
    9. leValue->setAlignment(Qt::AlignRight);
    10. infoLayout->addWidget(leValue);
    11. infoLayout->addStretch();
    12. mainLayout->addWidget(w);
    13. mainLayout->update();
    14. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget Shyness Syndrome

    the shyness is still there marcel but when i pull (skip)my scrollArea out of the pic i will see my info fine... this is really made me pull my hair today ...

    i am attaching my files in question hoping you can help me

    baray98
    Attached Files Attached Files
    Last edited by baray98; 20th September 2007 at 21:16.

  5. #5
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget Shyness Syndrome

    i think my problem is that my holder widget won't adjust it size after adding my lineEdits and labels. I already added the resize() for holder widgets but still no effect. what else can i do.

    baray98

  6. #6
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget Shyness Syndrome

    my solution was to re-assign the widget holder again in scrollArea everytime i add some more widgets in my holder.

    Qt Code:
    1. QWidget* holder = scrollArea->takeWidget()
    2.  
    3. // add stuff to holder
    4.  
    5.  
    6. scrollArea->setWidget(holder)
    To copy to clipboard, switch view to plain text mode 

    baray98 (kudos to marcel)

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
  •  
Qt is a trademark of The Qt Company.