Results 1 to 7 of 7

Thread: How to select a cell in a QTableView

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to select a cell in a QTableView

    Hello,

    How do I select a cell in a QTableView?

    The only thing I can find is QTableView::setSelection () but it requires a QRect.

    I like to specify row and column coordinates, how is that done?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to select a cell in a QTableView

    Hello,

    Take a look at QItemSelectionModel which is accessible via QAbstractItemView::selectionModel().
    J-P Nurmi

  3. #3
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to select a cell in a QTableView

    Thanks jpn;

    However that function takes a QModelIndex as parm. And that bugger does not have a constructor to feed row and column into.

    Qt Code:
    1. QModelIndex i; // ?
    2. table->selectionModel()->select(i, QItemSelectionModel::Select);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to select a cell in a QTableView

    QModelIndex represents a location in the model. See QAbstractItemModel::index():
    Qt Code:
    1. QModelIndex index = table->model()->index(row, column);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    JeanC (6th February 2008)

  6. #5
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to select a cell in a QTableView

    Sorry, It seems I asked the wrong question.

    This function indeed selects the cell. Good to know because it wasn't obvious to me.

    But I'm searching for the function to set that cell as the current, so when the arrow keys are pushed, the adjacent cell becomes the current.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to select a cell in a QTableView

    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    Dutchman (25th January 2012)

  9. #7
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to select a cell in a QTableView

    Thanks again. Great help here.

Similar Threads

  1. how to color a cell in a QTableView
    By JeanC in forum Qt Programming
    Replies: 13
    Last Post: 9th September 2015, 10:08
  2. how to remove the span set for a cell in QTableView
    By dandanch in forum Qt Programming
    Replies: 2
    Last Post: 21st October 2008, 11:22
  3. Word wrapping in a QTableWidget cell
    By jcooperddtd in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2007, 03:57
  4. Copying contents of QTableView cell to clipboard
    By Conel in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2006, 15:50
  5. QTableView change color of current Cell
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2006, 11:22

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.