PDA

View Full Version : QT Table Model



aekilic
20th January 2007, 15:07
Hello everybody

We are using QTableModel in our program, and from that table we would like to open another window.

We are doing the same thing for the TreeWidget by the help of the status tip, but for the table model we are not able to open another window from our table.

We really need help for this because we are locked!!!

Help us!

Regards

Efe

jpn
20th January 2007, 15:16
Any QWidget without a parent is a top level widget eg. a "window". QAbstractItemView has several signals (http://doc.trolltech.com/4.2/qabstractitemview.html#signals) you could act upon. When do you exactly want to show the window? What is it supposed to contain?

aekilic
20th January 2007, 16:25
for the tree widget we are using a signal like this in our main window

connect(treeCariAra, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotCariEdit(QTreeWidgetItem *)));

and void is like this in our main window.

void slotCariEdit(QTreeWidgetItem *item)
{
QTreeWidgetItem *itemcari = treeCariAra->currentItem();
if (itemcari == 0)
return;
formCari *ca = new formCari(this, itemcari->statusTip(0));
ca->exec();
return;
}


There is another place that we would like to reach the same data by a table model. For the Model we bring it our relatinal model like this

QSqlRelationalTableModel *cariler = new QSqlRelationalTableModel;
cariler->setTable("cari");
fiyatlistecari->setEditStrategy(QSqlRelationalTableModel::OnRowCha nge);
cariler->select();


tableCariler->setModel(cariler);
tableCariler->setItemDelegate(new QSqlRelationalDelegate(tableCariler));

After we bring our model we would like to make a link like to our formCari but we dont know which slots that we should be using.

AEK

jpn
20th January 2007, 16:53
I must admit that I don't really understand why to use status tips. But anyway, you should be able to reach the same functionality by connecting to QAbstractItemView::doubleClicked() signal. You must have a view there, showing the model, right? The model is not responsible for this kind of functionality..

aekilic
20th January 2007, 17:04
Please thing that i have a book window that i store my books to my database. I could see everything in a detail.

After that in a program samewhere i list all my books on a table model that i could see all of them in a table. But i would like to double click on one of the books from the table and see its details in my book window

jpn
20th January 2007, 17:15
Something like this should be quite close to the behavior with the tree widget:


connect(tableCariler, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(slotCariEdit(const QModelIndex&)));

void slotCariEdit(const QModelIndex& idx)
{
formCari ca(this, idx->data(Qt::StatusTipRole).toString());
ca.exec();
}

aekilic
20th January 2007, 17:38
After that in a program samewhere i list all my books on a table model that i could see all of them in a table. But i would like to double click on one of the books from the table and see its details in my book window

For the table model i was telling that a QRelationalTableModel not a tree widget, please help usss, :(

jpn
20th January 2007, 18:01
For the table model i was telling that a QRelationalTableModel not a tree widget, please help usss, :(
What do you want me to do? I already gave you the example code.

QRelationalTableModel, nor any other model handles double clicks. Model is there to provide some data for views. It's the view that handles double clicks and such. QAbstractItemView is the base class of all the views (QTreeView, QTableView, QListView) and offers a signal "doubleClicked(const QModelIndex&)" which is emitted whenever an index is double clicked in the view.

Didn't you notice any difference between the example snippet of mine and the corresponding QTreeWidget code of yours?

aekilic
20th January 2007, 18:20
i allready tried yours but i got a error like

error:request for member 'exec' in 'ca', which is of non-class type 'formCari'

jpn
20th January 2007, 18:30
i allready tried yours but i got a error like

error:request for member 'exec' in 'ca', which is of non-class type 'formCari'
The only difference to your example is that I allocated the dialog on the stack. A modal dialog is one of the cases where it is acceptable to allocate a QWidget on the stack. QDialog::exec() blocks as long as the modal dialog is accepted/rejected.

I assumed that "formCari" is a subclass of QDialog. You have used exec():




void slotCariEdit(QTreeWidgetItem *item)
{
...
formCari *ca = new formCari(this, itemcari->statusTip(0));
ca->exec();
...
}



So isn't "formCari" a subclass of QDialog? Or did you just mix operators "." and "->" up or even forget an include statement?

aekilic
24th January 2007, 10:39
We have solved the problem thank you very much,

We have tried to change some codes

connect(tableCariler, SIGNAL(doubleClicked(QModelIndex)), parent, SLOT(slotCarilerEdit(const QModelIndex)));

void slotCarilerEdit(const QModelIndex qm)
{

formCari *ce = new formCari(this, qm.sibling(qm.row(),0).data().toString());
ce->exec();
return;

}

Now we would like to do something else with this table. We would like to select something from the the table and send it to slotCarilerEdit with a push button. Any suggestion that we could use?

jpn
24th January 2007, 10:51
We would like to select something from the the table and send it to slotCarilerEdit with a push button. Any suggestion that we could use?
In Qt, how do you act in general to a button click (http://doc.trolltech.com/4.2/qabstractbutton.html#clicked)? The answer is; signals and slots (http://doc.trolltech.com/4.2/signalsandslots.html).

aekilic
24th January 2007, 11:36
Yes, we know about the signals and slots but, is it possible to select from table?

To tell more,

for the doubleClick

connect(tableCariler, SIGNAL(doubleClicked(QModelIndex)), parent, SLOT(slotCarilerEdit(const QModelIndex)));

the signal starts from tableCariler

we dont know how to connect tablecariler with a push button so that it will take the QModelIndex from tableCariler?

jpn
24th January 2007, 12:37
Maybe you could rely on the fact that the modal formCari dialog was shown when the user double clicked on some certain item. So as long as the dialog is blocking the users input, the same item remains active in the table view.

So maybe you could just connect to the clicked() signal and act in the view according to the current index.

aekilic
24th January 2007, 12:48
But if we say we have a slot like this

connect(pushInceleCari, SIGNAL(clicked(QModelIndex)), parent, SLOT(slotCarilerEdit(const QModelIndex)));

how could program could understand that there should be link between table and button?

jpn
24th January 2007, 12:57
connect(pushInceleCari, SIGNAL(clicked(QModelIndex)), parent, SLOT(slotCarilerEdit(const QModelIndex)));
You cannot do this. You cannot add random parameter types to signals. QPushButton offers a signal clicked(), not clicked(QModelIndex).



connect(pushInceleCari, SIGNAL(clicked()), parent, SLOT(doSomething()));

void doSomething()
{
QModelIndex idx = tableView->currentIndex();
...
}