Results 1 to 9 of 9

Thread: get and set current item in QTableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get and set current item in QTableView

    I do not want to set data. I only want to select a single cell at a position (row, column) which is not the current selected item. (Sorry, obviously my title was wrong)

    I know how to get the index of the current QModelIndex and from that I can get the information about the current row and column. But I can not create a ModelIndex and change its row and column. Therefore a setCurrentIndex is not helping, since its row and column can not be modified.

    There exists a selectRow and selectColumn, but I am looking for a selectCell(row, column).

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: get and set current item in QTableView

    Quote Originally Posted by pospiech View Post
    selectCell(row, column).
    =
    Qt Code:
    1. tableView->selectionModel()->select(tabelView->model()->index(row,colum), QItemSelectionModel::Select);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    waynew (14th February 2010)

  4. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: get and set current item in QTableView

    Thank you!

    I have now implemented the following to select and edit the next cell in the row.

    Qt Code:
    1. QModelIndex index = tableViewPowerDegree->currentIndex();
    2. int row = index.row() + 1;
    3. int column = 1;
    4. QModelIndex newIndex = tableViewPowerDegree->model()->index(row,column);
    5. tableViewPowerDegree->selectionModel()->select(newIndex, QItemSelectionModel::Select);
    6. tableViewPowerDegree->setCurrentIndex(newIndex);
    7. tableViewPowerDegree->setFocus();
    8. tableViewPowerDegree->edit(newIndex);
    To copy to clipboard, switch view to plain text mode 

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.