PDA

View Full Version : group box



me_here_me
6th September 2007, 16:50
I have tried hard to add a group box to the following set of widgets but failed, can someone point out a mistake!!



QLabel *labelSA = new QLabel("Self Analysis Tools");
QComboBox *comboBoxSA = new QComboBox(this);
// code
QLabel *labelST = new QLabel("Slope Threshold for Feature Peeling");
QSlider *sliderST = new QSlider(Qt::Horizontal);
// code
QLabel *labelMDFP = new QLabel("Min diff for FP b/w local min and local max");
QSlider *sliderMDFP = new QSlider(Qt::Horizontal);
// code
QLabel *labelID = new QLabel("Inter-DS Analysis");
QComboBox *comboBoxID = new QComboBox(this);
// code
QLabel *labelCT = new QLabel("Clamp Threshold for Inter-DS width difference");
QSlider *sliderCT = new QSlider(Qt::Horizontal);
// code
QLabel *labelZI = new QLabel("Zoom In/Out from CT Dataset");
QPushButton *buttonRC = new QPushButton("Reset Control Points");
// code
QPushButton *buttonZI = new QPushButton("Zoom In/Out");
// code

// a group box starting here

QVBoxLayout *vbox0 = new QVBoxLayout;
vbox0->addWidget(labelSA, 0, Qt::AlignTop);
vbox0->addWidget(comboBoxSA, 0, Qt::AlignTop);
vbox0->addWidget(labelST, 0, Qt::AlignTop);
vbox0->addWidget(sliderST, 0, Qt::AlignTop);
vbox0->addWidget(labelMDFP, 0, Qt::AlignTop);
vbox0->addWidget(sliderMDFP, 0, Qt::AlignTop);
// a group box starting here
vbox0->addWidget(labelID, 0, Qt::AlignTop);
vbox0->addWidget(comboBoxID, 0, Qt::AlignTop);
vbox0->addWidget(labelCT, 0, Qt::AlignTop);
vbox0->addWidget(sliderCT, 0, Qt::AlignTop);
// a group box starting here
vbox0->addWidget(labelZI, 0, Qt::AlignTop);
vbox0->addWidget(buttonRC, 0, Qt::AlignTop);
vbox0->addWidget(buttonZI, 0, Qt::AlignTop);
vbox0->addStretch(1);

QWidget *toolpage0 = new QWidget;
toolpage0->setLayout(vbox0);

toolbox->addItem(toolpage0, "Automatic Analysis of Datasets");


i tried to get help from the QT assistant but i get a run time error at the last line :( it seems as if i cannot have a group box and toolpage at the same time.

help needed

marcel
6th September 2007, 17:00
And what is the problem? It should be as easy as:


QWidget *toolpage0 = new QWidget(toolbox);
QGroupBox *box0 = new QGroupBox(toolpage0);
QVBoxLayout *vbox0 = new QVBoxLayout(box0);
vbox0->addWidget(labelSA, 0, Qt::AlignTop);
vbox0->addWidget(comboBoxSA, 0, Qt::AlignTop);
vbox0->addWidget(labelST, 0, Qt::AlignTop);
vbox0->addWidget(sliderST, 0, Qt::AlignTop);
vbox0->addWidget(labelMDFP, 0, Qt::AlignTop);
vbox0->addWidget(sliderMDFP, 0, Qt::AlignTop);
box0->setLayout(vbox0);

QVBoxLayout *toolLayout = new QVBoxLayout(toolpage0);
toolLayout->addWidget(box0);
toolPage0->setLayout(toolLayout);

toolbox->addItem(toolpage0, "Automatic Analysis of Datasets");




More or less :).

Regards

me_here_me
7th September 2007, 16:23
thanks for help

I was not handling the toolpage0 correctly, am a QT novoice :)

one more query:
1. my group boxes occupy the entire area rather then doing some kinda minimum area occupation. for instance, if I have two group boxes, they divide the entire available area between them. there is a lot of empty space within the group boxes as well. How can I keep the size of the group boxes to the minimum required.

best wishes

jpn
7th September 2007, 19:28
In Qt Designer you would add a spacer item, in code QBoxLayout::addStretch() is fine.