1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include "main_window.h"
main_window::main_window(QWidget *parent) : QMainWindow(parent)
{
//Main Window
QMdiArea *mdi = new QMdiArea;
setCentralWidget(mdi);
this->setWindowTitle("Main Window");
this->resize(550,400);
//command panel
QGroupBox *cmd = new QGroupBox("Add Tab");
cmd->setTitle("Command Panel");
cmd->setFixedWidth(250);
//init command panel
lbl_cmd = new QLabel("Nom de tabulation");
lbl_cmd->setAlignment(Qt::AlignHCenter);
str_lbl = "empty";
lbl_tab0 = new QLabel;
lbl_tab1 = new QLabel;
lblTab();
//button command panel
QPushButton *exit = new QPushButton("Exit");
QPushButton *table_buton = new QPushButton("TableView");
QPushButton *lbl_buton = new QPushButton("lblTab display");
QPushButton *stdItmModel_buton = new QPushButton("stdItmModel");
QPushButton *ouv_fichier_buton = new QPushButton("Not Use");
//TableView display
tabu = new QTabWidget;
//layout command panel
QHBoxLayout *h_bouton1 = new QHBoxLayout;
h_bouton1->addWidget(table_buton);h_bouton1->addWidget(lbl_buton);
QHBoxLayout *h_bouton2 = new QHBoxLayout;
h_bouton2->addWidget(stdItmModel_buton);h_bouton2->addWidget(ouv_fichier_buton);
QVBoxLayout *v_cmd = new QVBoxLayout;
v_cmd->addWidget(lbl_cmd);
v_cmd->addWidget(lbl_tab0);
v_cmd->addWidget(lbl_tab1);
v_cmd->addLayout(h_bouton1);
v_cmd->addLayout(h_bouton2);
v_cmd->addWidget(exit);
cmd->setLayout(v_cmd);
//Layout main window
QHBoxLayout *h_lay = new QHBoxLayout;
h_lay->addWidget(tabu);
h_lay->addWidget(cmd);
mdi->setLayout(h_lay);
//Connect
connect(table_buton,SIGNAL(clicked()),this,SLOT(tableView()));
connect(exit,SIGNAL(clicked()),this,SLOT(close()));
connect(lbl_buton,SIGNAL(clicked()),this,SLOT(str_lbl_chg()));
connect(stdItmModel_buton,SIGNAL(clicked()),this,SLOT(stdItmModel()));
}
void main_window::tableView()
{
for (int l(0);l<2;l++) //create 2 tableView
{
table = new QTableView;
QString str;
modele = new QStandardItemModel(5,2);
modele->setHeaderData(0,Qt::Horizontal,"Col 0");
modele->setHeaderData(1,Qt::Horizontal,"Col 1");
modele->setHeaderData(0,Qt::Vertical,"L 0");
modele->setHeaderData(1,Qt::Vertical,"L 1");
modele->setHeaderData(2,Qt::Vertical,"L 2");
modele->setHeaderData(3,Qt::Vertical,"L 3");
modele->setHeaderData(4,Qt::Vertical,"L 4");
for (int loopA(0);loopA<5;loopA++) //filing tablView
{
QString strLoopA;
stdIt = new QStandardItem;
stdIt->setText("value tab"+str.setNum(l)+" "+strLoopA.setNum(loopA)+"x0");
modele->setItem(loopA,0,stdIt);
stdIt = new QStandardItem;
stdIt->setText("value tab "+str.setNum(l)+" "+strLoopA.setNum(loopA)+"x1");
modele->setItem(loopA,1,stdIt);
}
table->setModel(modele);
tabu->addTab(table,"tab "+str.setNum(l)); //add TabWidget
}
}
void main_window::lblTab() //display in command panel
{
lbl_tab0->setText("tab0 value of row 1,col 0 : "+str_lbl);
lbl_tab1->setText("tab1 value of row 2,col 1 : "+str_lbl);
}
void main_window::str_lbl_chg() //mofidifcation command panel display
{
//str_lbl = "test ok"; // remove//before str_lbl to performed lbl modification test
str_lbl = stdItmModel()->item(1,0)->text();
str_lbl = stdItmModel()->item(2,1)->text();
lblTab();
}
QStandardItemModel *main_window::stdItmModel() // to return QStandardItemModel in active tabWidget
{
return tabu->currentWidget()->findChild <QStandardItemModel *>();
}
|