PDA

View Full Version : scrollBar in tabWidgets



baray98
15th September 2007, 09:10
i put a GroupBox inside my tabWidget and added lots of widgets in my groupBox, now how can i enable the scrollBar in my groupBox so that it i can view all my widgets.

or is there any other container that has a scrollBar that can be enable.

baray98

jpn
15th September 2007, 09:31
Sounds like you have this kind of structure:


QGroupBox
|-ChildWidget1
|-ChildWidget2
|- ...


Make it like this:


QGroupBox
|-QScrollArea
|-ChildWidget1
|-ChildWidget2
|-...

baray98
17th September 2007, 17:25
i still can not make it to scroll here my code below

(this is at the constructor and this class inherits QGroupBox)


frame = new QFrame (this);
scroll = new QScrollArea(this);
scroll->setWidget(frame);

mainLayout = new QVBoxLayout(this);
frame->setLayout(mainLayout);
mainLayout->addStretch();

QVBoxLayout * topLayout = new QVBoxLayout (this);
topLayout->addWidget(frame);

setLayout(topLayout);


i have a method called addInfo below



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

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


QString txtValue = QString("%1").arg(val, 2, 'f', 3);;

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

infoLayout->addStretch();

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

}



its all a mess please help

baray98

baray98
17th September 2007, 17:27
my full cocstructor looks like this

FrameInfo::FrameInfo(QWidget* parent )
:QGroupBox(parent)
{
//ctor
frame = new QFrame (this);
scroll = new QScrollArea(this);
scroll->setWidget(frame);

mainLayout = new QVBoxLayout(this);
frame->setLayout(mainLayout);
mainLayout->addStretch();

QVBoxLayout * topLayout = new QVBoxLayout (this);
topLayout->addWidget(frame);

setLayout(topLayout);
}

marcel
17th September 2007, 17:36
I am afraid the first code snippet you posted makes no freakin' sense :).

General QScrollArea usage: all widgets that you want to be contained by then scroll area have to be contained by a top level(container) widget. This container has to be added to the scroll area.

So, here's an example. You can add this to your custom group box constructor:


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

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



Now you can add widgets to holder widget, just like you did in the second code snippet, with the exception that you must not pass 'this' as parent for the new widgets, but the holder widget.

baray98
17th September 2007, 18:08
marcel, thanks for the quick reply .. but when i changed my code below all i see i a big widget inside my groupBox. I did not see any of my text edits and labels and there was no scroll bar either.


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);
}

FrameInfo::~FrameInfo()
{
//dtor
}

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

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


QString txtValue = QString("%1").arg(val, 2, 'f', 3);

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

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

}

this really confusing me

baray98

jpn
17th September 2007, 18:19
Try this:


void FrameInfo::addInfo(QString infoName, double val)
{
QHBoxLayout* infoLayout = new QHBoxLayout; // (holder); <-- remove parent, holder already has a layout installed (produces warning)
...
holder->adjustSize(); // <-- add this as last statement of addInfo()
}

baray98
17th September 2007, 18:23
thanks!!! a lot it work now ;)