#include <QtCore>
#include <QtGui>
#include "ui_dialog.h"
#include "dialog.h"
{
ui.setupUi(this);
model->setHeaderData(0, Qt::Horizontal, "Mois");
model->setHeaderData(1, Qt::Horizontal, "Facture");
palette.
setBrush((this)->backgroundRole
(),
QBrush(pixmap
));
(this)->setPalette(palette);
ui.treeView->setModel(model);
ui.treeView->setSelectionModel(selectionModel);
model
->setData
(model
->index
(row,
0,
QModelIndex()), month
);
model
->setData
(model
->index
(row,
1,
QModelIndex()), amount
);
month = "November";
amount = "10 Euros";
model
->setData
(model
->index
(row,
0,
QModelIndex()), month
);
model
->setData
(model
->index
(row,
1,
QModelIndex()), amount
);
ui.treeView->setRootIsDecorated( false );
// works perfect up to here, does not seem to connect then...:o
connect( ui.treeView, SIGNAL( doubleClicked(const ui.QModelIndex&) ),
this, SLOT( selection(const ui.QModelIndex&) ) );
}
void Dialog::selection(const QModelIndex& idx)
{
int row;
model
->setData
(model
->index
(row,
0,
QModelIndex()), month
);
model
->setData
(model
->index
(row,
1,
QModelIndex()), amount
);
QString col0
= model
->data
(idx.
sibling(idx.
row(),
0)).
toString();
QString col1
= model
->data
(idx.
sibling(idx.
row(),
1)).
toString();
model
->setData
(model
->index
(row,
0,
QModelIndex()), col0
);
model
->setData
(model
->index
(row,
1,
QModelIndex()), col1
);
}
#include <QtCore>
#include <QtGui>
#include "ui_dialog.h"
#include "dialog.h"
class QAbstractItemModel;
class QAbstractItemView;
class QItemSelectionModel;
class QStandardItemModel;
Dialog::Dialog(QWidget *parent) : QDialog(parent)
{
ui.setupUi(this);
QStandardItemModel *model = new QStandardItemModel(0, 2, this);
model->setHeaderData(0, Qt::Horizontal, "Mois");
model->setHeaderData(1, Qt::Horizontal, "Facture");
QPalette palette;
QPixmap pixmap = QPixmap("./images/bBackground.png");
palette.setBrush((this)->backgroundRole(), QBrush(pixmap));
(this)->setPalette(palette);
ui.treeView->setModel(model);
QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
ui.treeView->setSelectionModel(selectionModel);
model->removeRows(0, model->rowCount(QModelIndex()), QModelIndex());
QString month = "October";
QString amount = "5 Euros";
int row = model->rowCount(QModelIndex());
model->insertRows(row, 1, QModelIndex());
model->setData(model->index(row, 0, QModelIndex()), month );
model->setData(model->index(row, 1, QModelIndex()), amount );
month = "November";
amount = "10 Euros";
row = model->rowCount(QModelIndex());
model->insertRows(row, 1, QModelIndex());
model->setData(model->index(row, 0, QModelIndex()), month );
model->setData(model->index(row, 1, QModelIndex()), amount );
ui.treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui.treeView->setRootIsDecorated( false );
// works perfect up to here, does not seem to connect then...:o
connect( ui.treeView, SIGNAL( doubleClicked(const ui.QModelIndex&) ),
this, SLOT( selection(const ui.QModelIndex&) ) );
}
void Dialog::selection(const QModelIndex& idx)
{
QString month = "Selection added";
QString amount = "below:";
int row;
row = model->rowCount(QModelIndex());
model->insertRows(row, 1, QModelIndex());
model->setData(model->index(row, 0, QModelIndex()), month );
model->setData(model->index(row, 1, QModelIndex()), amount );
QString col0 = model->data(idx.sibling(idx.row(), 0)).toString();
QString col1 = model->data(idx.sibling(idx.row(), 1)).toString();
row = model->rowCount(QModelIndex());
model->insertRows(row, 1, QModelIndex());
model->setData(model->index(row, 0, QModelIndex()), col0 );
model->setData(model->index(row, 1, QModelIndex()), col1 );
}
To copy to clipboard, switch view to plain text mode
#ifndef UI_DIALOG_H
#define UI_DIALOG_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QTreeView>
class Ui_Dialog
{
public:
{
Dialog
->setObjectName
(QString::fromUtf8("Dialog"));
Dialog
->resize
(QSize(400,
230).
expandedTo(Dialog
->minimumSizeHint
()));
treeView
->setObjectName
(QString::fromUtf8("treeView"));
treeView
->setGeometry
(QRect(89,
60,
201,
80));
retranslateUi(Dialog);
} // setupUi
void retranslateUi
(QDialog *Dialog
) {
Q_UNUSED(Dialog);
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
#ifndef UI_DIALOG_H
#define UI_DIALOG_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QTreeView>
class Ui_Dialog
{
public:
QTreeView *treeView;
void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
Dialog->resize(QSize(400, 230).expandedTo(Dialog->minimumSizeHint()));
treeView = new QTreeView(Dialog);
treeView->setObjectName(QString::fromUtf8("treeView"));
treeView->setGeometry(QRect(89, 60, 201, 80));
retranslateUi(Dialog);
QMetaObject::connectSlotsByName(Dialog);
} // setupUi
void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
To copy to clipboard, switch view to plain text mode
Bookmarks