PDA

View Full Version : QWidget Shyness Syndrome



baray98
20th September 2007, 16:35
I have made a widget with the following

FrameInfo::FrameInfo(QWidget* parent )
:QGroupBox(parent)
{
//ctor

QVBoxLayout *topLayout = new QVBoxLayout(this);
QScrollArea* scrollArea = new QScrollArea(this);
topLayout->addWidget(scrollArea);
setLayout(topLayout);

//Now, for the group box
holder = new QWidget(scrollArea);
mainLayout = new QVBoxLayout(holder);
holder->setLayout(mainLayout);
mainLayout->addStretch();

scrollArea->setWidget(holder);
}

and a function like this



void FrameInfo::addInfo (QString infoName, QString val)
{
QHBoxLayout* infoLayout = new QHBoxLayout;

QLabel* lblValue = new QLabel (infoName,holder);
infoLayout->addWidget(lblValue);


QLineEdit* leValue = new QLineEdit (val,holder);
leValue->setReadOnly ( true );
leValue->setAlignment(Qt::AlignRight);
infoLayout->addWidget(leValue);


infoLayout->addStretch();
mainLayout->insertLayout(mainLayout->count()-1,infoLayout);

holder->adjustSize();
}


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

baray98
20th September 2007, 18:16
one more symptoms if i remove this line



holder->adjustSize(); //found in addInfo



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

marcel
20th September 2007, 19:11
Here you go(untested)


void FrameInfo::addInfo (QString infoName, QString val)
{
QWidget *w = new QWidget(holder);
QHBoxLayout* infoLayout = new QHBoxLayout(w);
QLabel* lblValue = new QLabel (infoName,w);
infoLayout->addWidget(lblValue);
QLineEdit* leValue = new QLineEdit (val,w);
leValue->setReadOnly ( true );
leValue->setAlignment(Qt::AlignRight);
infoLayout->addWidget(leValue);
infoLayout->addStretch();
mainLayout->addWidget(w);
mainLayout->update();
}

baray98
20th September 2007, 21:12
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

baray98
20th September 2007, 21:48
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

baray98
20th September 2007, 23:39
my solution was to re-assign the widget holder again in scrollArea everytime i add some more widgets in my holder.




QWidget* holder = scrollArea->takeWidget()

// add stuff to holder


scrollArea->setWidget(holder)


baray98 (kudos to marcel)