Results 1 to 9 of 9

Thread: QAbstractItemModel double click on current row

  1. #1
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Question QAbstractItemModel double click on current row

    Ok, i have QAbstractItemMode object with 4 columns and N rows.

    i need get data from column ID and current double-clicked row

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QAbstractItemModel double click on current row

    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?
    Last edited by ChrisW67; 27th January 2011 at 01:34.

  3. #3
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: QAbstractItemModel double click on current row

    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 ()

  4. #4
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: QAbstractItemModel double click on current row

    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?

  5. #5
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: QAbstractItemModel double click on current row

    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).

  6. #6
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: QAbstractItemModel double click on current row

    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::SingleSelecti on);
    proxyView->setSelectionBehavior(QAbstractItemView::SelectRow s);
    proxyView->setEditTriggers(QAbstractItemView::NoEditTriggers );

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

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QAbstractItemModel double click on current row

    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?

  8. #8
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: QAbstractItemModel double click on current row

    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.

  9. #9
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: QAbstractItemModel double click on current row

    Qt Code:
    1. proxyView->currentIndex().sibling(proxyView->currentIndex().row(),0).data().toString();
    To copy to clipboard, switch view to plain text mode 
    and all is work)

Similar Threads

  1. Replies: 6
    Last Post: 5th June 2009, 10:38
  2. Replies: 2
    Last Post: 12th January 2009, 00:24
  3. Double click distance
    By jbd in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2007, 23:13
  4. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 05:32
  5. Replies: 5
    Last Post: 12th January 2006, 16:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.