PDA

View Full Version : QAbstractItemModel double click on current row



core_st
26th January 2011, 21:24
Ok, i have QAbstractItemMode object with 4 columns and N rows.
http://i.piccy.info/i5/11/17/1011711/Image_11.png
i need get data from column ID and current double-clicked row

ChrisW67
26th January 2011, 22:02
You need to concentrate on the view, not the model. I assume it is a QTableView. The QAbstractItemView::doubleClicked() signal will give you the model index that was clicked on. You now have the QModelIndex::row() and can easily build another QModelIndex with the column set to 0 ( or whichever model column is the ID) using QModelIndex::sibling() or some other method.

Normally double-clicking would put the affected cells into edit mode. Is the model editable or not?

helloworld
26th January 2011, 22:09
I'm not sure if I understand your question but in case you are looking for a way to find the currently selected row(s), you'll need to look in the view object displaying the data rather than the model itself.

QAbstractItemView::selectedIndexes ()

QAbstractItemView::selectionModel ()

core_st
26th January 2011, 22:36
Editmode is off. One click whole row is selected.

You need to concentrate on the view, not the model. I assume it is a QTableView.
no. i will use QAbstractItemModel because it's necessary for my project. Any ideas?

helloworld
26th January 2011, 23:12
You must be using some sort of view, since QAbstractItemModel doesn't display anything itself. What ChrisW67 meant was that, to judge from your uploaded image, your code seems to use QTableView to present the data.

Can you post the part of your code where you instantiate your model subclass (possibly in MainWindow or something similar).

core_st
27th January 2011, 00:50
Oh, sorry. I use QTreeView for display data

proxyModel = new QSortFilterProxyModel;
proxyModel->setDynamicSortFilter(true);


proxyView = new QTreeView;
proxyView->setRootIsDecorated(false);
proxyView->setAlternatingRowColors(true);
proxyView->setModel(proxyModel);
proxyView->setSortingEnabled(true);
proxyView->setSelectionMode(QAbstractItemView::SingleSelectio n);
proxyView->setSelectionBehavior(QAbstractItemView::SelectRows );
proxyView->setEditTriggers(QAbstractItemView::NoEditTriggers) ;

oh, qtreeview has slot doubleclicked. think with using that slot my problem must be solved.

ChrisW67
27th January 2011, 01:13
Good. Would you mind editing your original post and uploading the image to this forum so that it doesn't go missing and we are not using someone else's bandwidth?

core_st
27th January 2011, 13:46
have some question: double click wasn't problem. But by double click on qtreeview object i can get qmodelindex - current row and current column. But i need data from current row and column ID only.

core_st
27th January 2011, 16:39
proxyView->currentIndex().sibling(proxyView->currentIndex().row(),0).data().toString();
and all is work)