Results 1 to 2 of 2

Thread: How to connect two tableView widgets

  1. #1
    Join Date
    Dec 2010
    Posts
    11
    Thanks
    1

    Default Re: How to connect two tableView widgets

    Hi all,

    I have main window with two tableView widgets. The data has primary key and foreign key and I want to connect it using onclick slot. The idea is to update the second table when click on the first and modify where part in the query.

    The problem is that I can get the index of the first table but i need the value. Here is the code of the slot:

    Qt Code:
    1. void SBTable::on_tableView_clicked(QModelIndex index)
    2. {
    3. QString num;
    4.  
    5. num = this->db->model->data(this->db->model->index(index.row(), 0)).toString();
    6.  
    7. this->SBMessageBox("idx: " + num + ".");
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance!


    Added after 49 minutes:


    I found a solution:

    Qt Code:
    1. num = this->ui->tableView->model()->data(
    2. this->ui->tableView->model()->index(index.row() ,
    3. 0)).toString();
    To copy to clipboard, switch view to plain text mode 

    One other problem appear now:

    How to set the model to the second tableView?
    Last edited by kode; 22nd December 2010 at 12:13.

  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: How to connect two tableView widgets

    The index passed in to the slot encodes the source model. Also, the QModelIndex::sibling() method can be useful.
    Qt Code:
    1. num = this->ui->tableView->model()->data(
    2. this->ui->tableView->model()->index(index.row() ,
    3. 0)).toString();
    To copy to clipboard, switch view to plain text mode 
    becomes something like:
    Qt Code:
    1. num = index.sibling(index.row(), 0).data().toString();
    To copy to clipboard, switch view to plain text mode 

    How you adjust the second view's content is entirely dependent on how you have constructed the model and view. If it is a simple string filter then I'd be tempted to use the base model through a QSortFilterProxyModel. Then just use the QSortFilterProxyModel::setFilterFixedString() slot.

Similar Threads

  1. Replies: 12
    Last Post: 8th October 2010, 16:19
  2. Replies: 2
    Last Post: 6th October 2010, 03:34
  3. Replies: 16
    Last Post: 16th February 2010, 13:17
  4. Designer doesn't connect the widgets
    By martinb0820 in forum Qt Tools
    Replies: 6
    Last Post: 6th November 2008, 14:18
  5. Widgets in TableView
    By boonie in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2006, 19:55

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.