Any QWidget without a parent is a top level widget eg. a "window". QAbstractItemView has several signals you could act upon. When do you exactly want to show the window? What is it supposed to contain?
Any QWidget without a parent is a top level widget eg. a "window". QAbstractItemView has several signals you could act upon. When do you exactly want to show the window? What is it supposed to contain?
J-P Nurmi
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::OnRowCh ange);
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
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..
J-P Nurmi
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
Something like this should be quite close to the behavior with the tree widget:
Qt Code:
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(); }To copy to clipboard, switch view to plain text mode
J-P Nurmi
aekilic (24th January 2007)
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?
J-P Nurmi
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():
So isn't "formCari" a subclass of QDialog? Or did you just mix operators "." and "->" up or even forget an include statement?
Last edited by jpn; 20th January 2007 at 19:06. Reason: spelling error
J-P Nurmi
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?
In Qt, how do you act in general to a button click? The answer is; signals and slots.
J-P Nurmi
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?
Last edited by aekilic; 24th January 2007 at 11:51.
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.
J-P Nurmi
Bookmarks