Results 1 to 2 of 2

Thread: QTableView, selected row?

  1. #1
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question QTableView, selected row?

    Hello,

    I try to detect cases where there is a selection or none, on a QTableView which allows single rows selection.

    What's wrong? Code below doesn't fail, but I don't get the popups "xLogWarning()" calls should produce...

    I'm also wondering about the model giving me its value for selected row and column of my choice...

    I also read this topic: http://www.qtcentre.org/threads/1046...t-selected-row

    Thanks for helping.

    Qt Code:
    1. m_tableView = new QTableView();
    2. m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    3. m_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // Get selected image
    2. QItemSelectionModel* selectedModel = m_tableView->selectionModel();
    3. if(!selectedModel->hasSelection()) {
    4. xLogWarning(tr("No image selected"));
    5. return;
    6. }
    7. xLogWarning(tr("There is an image selected"));
    8. QModelIndexList selection = selectedModel->selectedIndexes();
    9. xLogWarning(tr("selected row: %1").arg(selection[0].row()));
    10. xLogWarning(tr("Selected image: %1").arg(m_model.getObjectIdAt(selection[0].row())));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QTableView, selected row?

    Hello,

    Doing debug right now, what's wrong? My "selectedIndex" variable below looks strange, and the same whatever I select a row or not before clicking on the button besides the QTableView.

    Qt Code:
    1. QItemSelectionModel* selectedModel = m_tableView->selectionModel();
    2. QModelIndex selectedIndex = selectedModel->currentIndex();
    To copy to clipboard, switch view to plain text mode 

    qitemselectionmodel_currentindex.jpg


    Added after 19 minutes:


    OK, my debug was wrong, the above code works well.
    Last edited by postb99; 25th February 2014 at 16:22.

Similar Threads

  1. QTableView get selected row
    By raphaelf in forum Qt Programming
    Replies: 8
    Last Post: 12th July 2013, 04:35
  2. QTableView selected a full row
    By pmjz in forum Qt Programming
    Replies: 0
    Last Post: 28th October 2011, 01:22
  3. Selected row bigger than others in QTableView
    By JuanMO in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2010, 17:48
  4. QTableView Signal when nothing is selected
    By djjkotze in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2010, 16:00
  5. Deleting selected row from a QTableView
    By Ferric in forum Newbie
    Replies: 9
    Last Post: 15th January 2010, 09:32

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.