PDA

View Full Version : addWidget other place than setCentralWidget()



darkrptyp
18th November 2011, 10:21
void MainWindow::setGUI()
{
QWidget* frame = new QWidget;
QToolButton *toolButton;
_layout = new QVBoxLayout;
frame->setLayout(_layout);
tabWidget = new QTabWidget();
tab = new QWidget();
pushButton = new QPushButton(tab);
tabWidget->addTab(tab, QString());
_layout->addWidget(tabWidget);
scrollArea = new QScrollArea;
scrollArea->setWidget(frame);
scrollArea->setWidgetResizable(true);
setCentralWidget(scrollArea);
}

This above works fine, i got scrollArea->tabWidget->tab->pushButton, but if I'd like to addWidget from other method/function to this layout i am not able to add new widget to "tab". Everything is under tabWidget which is part of scrollArea (centralWidget).


void MainWindow::addToGUI()
{
while(true)
{

QGroupBox* newGB = new QGroupBox("group box");
QFormLayout* form_layout = new QFormLayout;

layout->addRow("ID1", new QLabel(function()));
layout->addRow("ID2", new QLabel(function()));
layout->addRow("ID3", new QLabel(function()));

newGB->setLayout(layout);
this->_layout->addWidget(newGB); // i want this in tabWidget->tab, i know that there is setCentralWIdget(scrollArea) and that is why i get this under tabWidget.
}
}


Here is what i mean -> 7114

How to solve this?

Oleg
18th November 2011, 14:10
Just add needed widgets to QTabWidget's tab (better place layout there), not to main window's layout.

darkrptyp
18th November 2011, 16:21
Just add needed widgets to QTabWidget's tab (better place layout there), not to main window's layout.

I'm QT noob, and i'm not sure what u mean. since a few yeras i only use php oop.
I removed this line "this->_layout->addWidget(newGB);" from addToGUI(), and wrote "_layout->addWidget(newGB);" in setGUI() but I got app crash, that exe is not responding (headers are correct).

Oleg
18th November 2011, 20:35
1. BTW, create all widgets in visual editor, it's much easier.
2. Add layout to your tab


tab->setLayout(new QVBoxLayout());

3. Add QPushButton and QGroupBox to that layout


tab->layout()->addWidget(new QPushButton());
tab->layout()->addWidget(newGB);