[Solved] Error with layouts
-
wrote on 8 Aug 2011, 10:57 last edited by
hello everybody.
Cant we place a layout on to another Layout??? I get the following warning when I run the application
"attempting to set QLayout on Qwidget which has already a layout". I dont get the output either, is it because of this warning?
alfah
-
wrote on 8 Aug 2011, 11:07 last edited by
This warning tells you the widget you want to set a layout on has already one and you cannot add another one on the same level.
You can use a layout IN another layout though.
-
wrote on 8 Aug 2011, 11:13 last edited by
This warning appears while attempting this.
A vlayout is being set to a QWidget and this QWidget is set to a tabWidget.can this warning not give the desired output?
Could you explain on how one layout can be used inside another?alfah
-
wrote on 8 Aug 2011, 11:16 last edited by
Are you using Qt Designer or code?
-
wrote on 8 Aug 2011, 11:21 last edited by
everythig is code written. Im jus trying to achieve my tabs not refreshing through some alternative.
Instead of creating the obj of the class and putting them in tab, i tried creating a layout and then assign them to a tab. -
wrote on 8 Aug 2011, 11:34 last edited by
Just use addLayout (as you would use addWidget) to add another layout to a layout.
Can you provide some code so we can take a look at it?
-
wrote on 8 Aug 2011, 11:38 last edited by
example with 3 buttons in layout in QTabwidget:
@ horizontalLayout = new QHBoxLayout(Dialog);
tabWidget = new QTabWidget(Dialog);
tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
tab = new QWidget();
tabWidget->addTab(tab, QString());
tab_2 = new QWidget();
horizontalLayout_2 = new QHBoxLayout(tab_2);
verticalLayout = new QVBoxLayout();
pushButton = new QPushButton(tab_2);verticalLayout->addWidget(pushButton); pushButton_2 = new QPushButton(tab_2); verticalLayout->addWidget(pushButton_2); pushButton_3 = new QPushButton(tab_2); verticalLayout->addWidget(pushButton_3); horizontalLayout_2->addLayout(verticalLayout); tabWidget->addTab(tab_2, QString()); tab_3 = new QWidget(); tabWidget->addTab(tab_3, QString()); horizontalLayout->addWidget(tabWidget);@
EDIT : this is code generated by Qt Designer in a ui_yourForm.h and helps a lot to learn how to use QLayouts and QWidgets in it.
-
wrote on 8 Aug 2011, 11:43 last edited by
hey
I have solved it using another alternative. Instead of creating class instances and showing every time. I manually created the whole form with all the labels and text boxes. Put all of them in a layout. And placed the layout in the tabs.@
void MainWindow::displayTabs()
{
tabWidget = new QTabWidget;
pCalender = new QWidget;
pHistory = new QWidget;
pStatistics= new QWidget;pCalender->setStyleSheet("background-color: rgb(224, 220, 201);"); pHistory->setStyleSheet("background-color: rgb(224, 220, 201);"); pStatistics->setStyleSheet("background-color: rgb(224, 220, 201);"); connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(a(int))); tabWidget->addTab(pCalender,tr("Calender")); tabWidget->addTab(pHistory,tr("History")); tabWidget->addTab(pStatistics,tr("Statistics")); setCentralWidget(tabWidget);
}
void MainWindow::a(int index)
{
switch(index)
{
case 0:
calCal();
break;case 1: calHist(); break; case 2: calStat(); break; }
}
void MainWindow::calCal()
{
CalenderForm *c=new CalenderForm();
qDeleteAll(pCalender->children());
pCalender->setLayout(c->vLayout);
pCalender->show();
}void MainWindow::calHist()
{
qDebug()<<"hello World";
test *t=new test();
qDeleteAll(pHistory->children());
pHistory->setLayout(t->vLayout);
t->DisplayHistory();
pHistory->show();}
@:) :)
alfah -
wrote on 9 Aug 2011, 06:50 last edited by
so solved :)
1/9