[Solved] Error with layouts
-
-
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.
-
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