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
|
//le header
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
#include <vector>
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[2][2];
private slots:
void FillIn();
private:
QTableWidget *tabM;
//QTableWidgetItem *it;
QPushButton * generer;
QVBoxLayout * vbox;
};
#endif
//FenPrincipale.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
FenPrincipale::FenPrincipale()
{
// QTableWidget *tabM =new QTableWidget(this);
tabM =new QTableWidget(this);
tabM->setRowCount(2);
tabM->setColumnCount(2);
generer = new QPushButton("&Générer !",this);
// generer->move(50,50);
QVBoxLayout* vbox = new QVBoxLayout();
vbox->addWidget(generer);
vbox->addWidget(tabM);
this->setLayout(vbox);
for (int r = 0; r < 2; r++) {
for (int c = 0; c < 2; c++) {
QTableWidgetItem *it = new QTableWidgetItem;
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
//qDebug() <<it;
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < 2; r++) {
for (int c = 0; c < 2; c++) {
QTableWidgetItem *it =new QTableWidgetItem;
it = tabM->item(r,c);
Q_ASSERT(it);
it=(tabM->item(r,c));
tabM->setItem(r, c, it);
qDebug() <<it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1)? true: false;
qDebug() <<M[r][c];
}
}
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
} |
Partager