[Solved]creating tabs
-
oops, I meant
@
centralWidget()->setLayout(mainLayout);
@Eddy, looks like it is form created from designer, so central widget should be there.
-
-
eddy,
@
Tabs::Tabs(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Tabs)
{
ui->setupUi(this);
tabWidget = new QTabWidget;
tabWidget->addTab(new QWidget,tr("History"));
tabWidget->addTab(new QWidget,tr("Calender"));
tabWidget->addTab(new QWidget,tr("Statistics"));
mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
centralWidget()->setLayout(mainLayout);}
@i still do not know how to make individual buttons on each tab :(
alfa
-
[quote author="alfah" date="1312355523"]eddy,
@
Tabs::Tabs(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Tabs)
{
ui->setupUi(this);
tabWidget = new QTabWidget;
tabWidget->addTab(new QWidget,tr("History"));
tabWidget->addTab(new QWidget,tr("Calender"));
tabWidget->addTab(new QWidget,tr("Statistics"));
mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
centralWidget()->setLayout(mainLayout);}
@i still do not know how to make individual buttons on each tab :(
alfa
[/quote]You can event add custom widgets to the tab widget, so go this way:
@
Tabs::Tabs(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Tabs)
{
ui->setupUi(this);
tabWidget = new QTabWidget;QWidget* pHistory = new QWidget; // fill pHistory here QPushButton* p = new QPushButton(tr("my text"), pHistory); tabWidget->addTab(pHistory,tr("History")); tabWidget->addTab(new QWidget,tr("Calender")); tabWidget->addTab(new QWidget,tr("Statistics")); mainLayout = new QVBoxLayout; mainLayout->addWidget(tabWidget); centralWidget()->setLayout(mainLayout);
}
@ -
in that case use cinrin's solution :
for example :
@ QPushButton* ppp = new QPushButton("testing" );
QHBoxLayout* hhh = new QHBoxLayout();
hhh->addWidget(ppp);
ui->tabWidget->widget(1)->setLayout(hhh);@I set up an example layout for you to control size and position.
EDIT : this time Gerolf was faster ;)
-
gerolf,
yea i could make buttons. Now im working on somethin a bit more complex than a single button.
I have made a calender using an array of buttons, its the same thing like the default calender.Would it be possible to put in the whole calender in to one of the tab, jus as you have created a single button.???
It requires mainly 4 funtions to create the whole calender
@
initMemberVariable();initMonthYear(); initWeekDay(); createLayout();
@
@
bool CalenderForm::initMemberVariable()
{selectedDate=QDate::currentDate(); controlsLayout = new QGridLayout(); monthValue=selectedDate.month(); pLabelStatus=new QLabel; pLabelStatus->setStyleSheet("color:black"); for(int i=0;i<6;i++) { for(int j=0;j<7;j++) { cellBut[i][j]=new QPushButton(this); connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction())); cellBut[i][j]->setFlat(true); } } return true;
}
@This is where the buttons are created. I want them to be created in the calender tab.
Could you guide me on how to go abt it?
alfa
-
[quote author="Eddy" date="1312356252"]in that case use cinrin's solution :
for example :
@ QPushButton* ppp = new QPushButton("testing" );
QHBoxLayout* hhh = new QHBoxLayout();
hhh->addWidget(ppp);
ui->tabWidget->widget(1)->setLayout(hhh);@I set up an example layout for you to control size and position.
EDIT : this time Gerolf was faster ;)[/quote]
what is widget(1)??
-
bq. This is where the buttons are created. I want them to be created in the calender tab.
Could you guide me on how to go abt it?try this
@ QGridLayout* grid = new QGridLayout();
for(int i=0;i<6;i++) { for(int j=0;j<7;j++) { cellBut[i][j]=new QPushButton(QString("%1 , %2").arg(i).arg(j)); connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction())); cellBut[i][j]->setFlat(true); grid ->addWidget(cellBut[i][j],i,j); } } ui->tabWidget->widget(1)->setLayout(grid );@
-
Thanks everybody :)
got it fixed :) this is wat Ive used jus in case somebody else needs it. My calender is put in vlayout. so my tabwidget has now the vLayout.
@
QVBoxLayout *vLayout=new QVBoxLayout; tabWidget = new QTabWidget; QWidget* pCalender = new QWidget; QWidget* pHistory = new QWidget; QWidget* pStatistics= new QWidget; tabWidget->addTab(pCalender,tr("Calender")); tabWidget->addTab(pHistory,tr("History")); tabWidget->addTab(pStatistics,tr("Statistics")); tabWidget->widget(0)->setLayout(vLayout);
@
Last one, how to show another form when i click a tab. I have a function to show the history form. how do i call the functionwithout having to put a button on the History Tab??? :(
alfah
EDIT : i meant History Tab
-
eddy
There is an EDIT in my previous post :) I meant history tab not history form.I have made these tabs at the top to replace two buttons i have in the form.
Its easier to switch between the tabs, so i have history button which when clicked goes to another form, the history form.Now im tryin to put the same thing into the tab. ie when I click the history tab, it should go to the history form
This is my function which opens the history form
@
bool CalenderForm::showHistoryFrm()
{HistoryForm *hHistoryFrm=new HistoryForm; hHistoryFrm->show(); setCentralWidget(hHistoryFrm); hHistoryFrm->DisplayHistory(); return true; delete hHistoryFrm;
}
@alfah