Originally Posted by
^NyAw^
Hi,
I'm trying to create a front-end GUI for my application. It consist on some lists coded in C++ for me. It have list objects that have other lists, ...
Now I want to create a TreeView to show the data. I'm reading the Qt doc about MVC. I can see that I could create use a delegate to edit the data of the tree, but I don't know how to change my internal data.
You can read data from sql text xml CSV to edit you write a model
QStringListModel is used to store a simple list of QString items.
QStandardItemModel manages more complex tree structures of items, each of which can contain arbitrary data.
QDirModel provides information about files and directories in the local filing system.
QSqlQueryModel, QSqlTableModel, and QSqlRelationalTableModel are used to access databases using model/view conventions.
Another question, the method "createEditor" of the delegate could create a widget specific to the data that have to edit? Imagine that I have a treeItem that is an int, other treeItem that is a float, other that is a QString. Could it be possible?
createEditor ....
You can write each class wo is subclass from QWidget edit or not edit you set a correct flag... button QLabel combobox ecc... to edit or display...
Qt::ItemFlags flags = QSqlQueryModel::flags(index);
if (index.column() == 1 || index.column() > 11) {
flags |= Qt::ItemIsSelectable;
..............
{
if (index.column() == 11 || index.column() == 7 ) {
editor->setDisplayFormat("dd.MM.yyyy");
editor->setCalendarPopup(true);
return editor;
} else if (index.column() == 0) {
Base_Button *editora = new Base_Button(parent);
connect( editora , SIGNAL(OpenItem(int)), this , SLOT(Omodusa(int)));
/* other connect flat button .... */
return editora;
} else {
}
}
QWidget *BaseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 11 || index.column() == 7 ) {
QDateTimeEdit *editor = new QDateTimeEdit(parent);
editor->setDisplayFormat("dd.MM.yyyy");
editor->setCalendarPopup(true);
return editor;
} else if (index.column() == 0) {
Base_Button *editora = new Base_Button(parent);
connect( editora , SIGNAL(OpenItem(int)), this , SLOT(Omodusa(int)));
/* other connect flat button .... */
return editora;
} else {
return QItemDelegate::createEditor(parent, option, index);
}
}
To copy to clipboard, switch view to plain text mode
My internat data structure is changing by user interaction and I want to show the current state. There are items that will be deleted, others that will be created and inserted in it's properly position.
,
Set flag to edit or only display ...
{
if (index.column() < 2 || index.column() > 11) {
return false;
}
int id = data(primaryKeyIndex).toInt();
int lasteditingline = index.row();
clear();
bool ok;
if (index.column() == 9) {
saxi
= QString("update TABLEX set LANGUAGE = '%1' where ID = '%2'").
arg(value.
toString().
toUpper()).
arg(id
);
update query && return true or false...
bool SearchModel::setData(const QModelIndex &index, const QVariant &value, int role )
{
if (index.column() < 2 || index.column() > 11) {
return false;
}
QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 0);
int id = data(primaryKeyIndex).toInt();
int lasteditingline = index.row();
clear();
bool ok;
QString saxi;
if (index.column() == 9) {
saxi = QString("update TABLEX set LANGUAGE = '%1' where ID = '%2'").arg(value.toString().toUpper()).arg(id);
update query && return true or false...
To copy to clipboard, switch view to plain text mode
Begin to play on MVC examples/sql sqlite3 is running fast and easy ....
Bookmarks