#include <QtGui>
#include "application.h"
--
--
#include ..
MyApplication::myApplication()
{
---
createActions();
createMenus();
createToolBars();
createStatusBar();
addItems();
---
----
}
void MyApplication::createActions()
{
---
}
void MyApplication::createMenus()
{
---
}
void MyApplication:: createToolBars()
{
// used to creating the toolbar
----some code
}
void MyApplication:: createStatusBar()
{
// status bar
------some code
}
void MyApplication::addItems()
{
//add all the item in my application to main app
setCentralWidget(mainWidow); // Central Widget
addPage1Tabitems(); // ???
addPage2items();
addPage3items();
---
addPageNitems();
--
}
//Help needed for tab widgets containing table widgets in different tabs
Void MyApplication:: addPage1Tabitems()
{
// I need help with this function .. sample code may help greatly
// plz point out where I am going wrong!!
// I am not using Designer
//I tried the following
page1MainWidget
=new QWidget;
// its added to the central stacked widget , contains the tab widgetQLabel * page1MainWidget Title
= new QLabel ("<center><font size=\"4\">"+tr
("Some Name ")+":</font></center>");
QLabel * page1Tab1Title
= new QLabel ("<center><font size=\"4\">"+tr
("Pag1 Tab1 ")+":</font></center>");
tab1Table ->setRowCount(9);
tab1Table ->setColumnCount(7);
tab1Table ->setParent(this);
//table -> verticalHeader()->hide();
tab1Table -> setSortingEnabled(false);
tab1Table -> setItemDelegate(&tab1Table_Delegate); //delegate define in separate files
-- similar code and layout as in addPage2item () tables .. see next function below
tab1Table ->setLayout(layoutTab1Table);
// page1Tab1Widget ->addWidget(tab1Table); // getting error , what to do??
-- otherwise define layout for page1Tab2Widget.. dot know if that’s how it should be??
-- if addLayout need to be used here??
-- page1Tab1WidgetLayout-> addWidget(tab1Table); //??
-- page1Tab1-> setLayout (page1Tab1WidgetLayout); //??
-- page1TabWidget -> addTab(page1Tab1,tr("Page1Tab1 "));
//------------------------------------------------------------------------
//Tab 2 of the Tab widget in Page 1
//------------------------------------------------------------------------
page1Tab1Label
= new QLabel("<font size=\"5\">" "Some Name</font>");
-- similar code as above for table & layout
---
---
tab2Table ->setLayout(layoutTab2Table);
//page1Tab2Widget ->addWidget(tab2Table); // getting error , what to do??
--otherwise define layout for page1Tab2Widget
-- if addLayout need to be used here??
-- page1Tab2WidgetLayout-> addWidget(tab1Table); //??
-- page1Tab2-> setLayout (page1Tab2WidgetLayout); //??
-- page1TabWidget -> addTab(page1Tab2,tr("Page1Tab2 "));
//-----------------------------------------
// Similarly for other tabs
/------------------------------------------
//Finally stitching the tab widget to the central stacked widget
horizontalLayout->addWidget(page1TabWidget);
page1MainWidget ->setLayout(horizontalLayout);
mainWidow->addWidget(page1MainWidget);
}
// This table widget in page 2 of the stacked widget works , I want to add same/similar multiple table widgets in tabs in Page1 [addPage1Tabitems()]
Void MyApplication :: addPage2Items()
{
QLabel * appPage2Title
= new QLabel ("<center><font size=\"4\">"+tr
("Some Name")+":</font></center>");
appTablePage2->setRowCount(9);
appTablePage2->setColumnCount(7);
appTablePage2->setParent(this);
//table -> verticalHeader()->hide();
appTablePage2-> setSortingEnabled(true);//old false
appTablePage2-> setItemDelegate(&appTablePage2_Delegate); //suitable delegate defined in
//separate files
appTablePage2labels << tr("Label1") <<tr("Label2") << tr("Label3") << tr("Label14") << tr("Label5")<<tr("La6el1")<<tr("Label7); // lables/column can be added or deleted
universalAppTablePage2labels<<"Lable1"<<"Lable2"<<"Lable2 Lable3"<<"Lable4"<<"Lable5"<<"Lable6"<<"Lable7";
// Setting lables and column width
appTablePage2->setHorizontalHeaderLabels(appTablePage2labels);
for(int i=0;i<2;i++)
{
appTablePage2 -> setColumnWidth(i,100);
};
for(int i=2;i<= appTablePage2->columnCount()-1;i++)
{
appTablePage2 -> setColumnWidth(i,960/( appTablePage2->columnCount()-1));
}
appTablePage2 -> horizontalHeader() -> setStretchLastSection(true);
//Add push buttons for adding columns and rows to table
newABRow = new QPushButton(tr("Add Row"));
newABCmn = new QPushButton(tr("Add Column"));
delABCmn = new QPushButton(tr("Delete Column"));
delABRow = new QPushButton(tr("Delete Row"));
newABRow -> setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
newABCmn -> setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
delABRow-> setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
delABCmn-> setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
//make connections to the slots
connect(newABRow,SIGNAL(clicked()),this,SLOT(newRowAB()));
connect(delABRow,SIGNAL(clicked()),this,SLOT(delRowAB()));
connect(newABCmn,SIGNAL(clicked()),this,SLOT(newColumnAB()));
connect(delABCmn,SIGNAL(clicked()),this,SLOT(delColumnAB()));
connect( appPage2,SIGNAL(focusLost()),this,SLOT(saveAppPage2()));
//Layouts:
abVl=new QVBoxLayout;
abVl->addWidget(appPage2Title);
abVl->addWidget(appTablePage2);
abVl -> setSizeConstraint(QLayout::SetNoConstraint);
abLabel = new QLabel(tr("Some Name"));
abCombo = new QComboBox;
--some code for abCombo and Layout
abLayout = new QHBoxLayout;
abLayout -> addWidget(abLabel);
abLayout -> addWidget(abCombo);
abLayout -> setAlignment(Qt::AlignRight);
abCenterLayout = new QHBoxLayout;
abCenterLayout->addWidget(newABCmn);
abCenterLayout->addSpacing(50);
abCenterLayout->addWidget(delABCmn);
abCenterLayout->addSpacing(50);
abCenterLayout->addWidget(newABRow);
abCenterLayout->addSpacing(50);
abCenterLayout->addWidget(delABRow);
abCenterLayout-> setAlignment(Qt::AlignHCenter);
abBHl=new QHBoxLayout;
abBHl->addLayout(abCenterLayout);
abBHl->addSpacing(50);
abBHl->addLayout(abLayout);
abBHl-> setAlignment(Qt::AlignHCenter);
abVl->addLayout(abBHl);
QHBoxLayout *layoutAB= new QHBoxLayout;
layoutAB->addSpacing(10);
layoutAB->addLayout(abVl);
layoutAB->addSpacing(10);
appPage2->setLayout(layoutAB);
mainWidow->addWidget(appPage2);
};
void MyApplication::ChangetoPage2()
{
---some code
mainWidow->setCurrentIndex(1);
};
void MyApplication::ChangetoPage3()
{
---some code
mainWidow->setCurrentIndex(2);
};
----
----
void MyApplication::ChangetoPageN()
{
---some code
mainWidow->setCurrentIndex(N-1);
};
---similarly for other pages for changing the index on action
--some more code
--slot codes ..
Bookmarks