Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting a table cell content through a proxy from a model
QtWS25 Last Chance

Getting a table cell content through a proxy from a model

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    I have an qtableview with a model and a proxy (QSortFilterProxyModel).
    I know that when I'd like to get a specific cell content I need a modelindex from the proxy (and from the model).
    What I want:
    when the user clicks on a row on the table, he get a cell content from the selected row (from the 0. column).

    How can I solve this? Can sy send me a code snippet?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danut.iurascu
      wrote on last edited by
      #2

      You can take a look at this example "https://gitorious.org/qt-training/course-material/trees/c71ad30d0b7271b70af39c5aa47d5bd6ad77005c/addon/modelview/ex-sortfiltertableview":https://gitorious.org/qt-training/course-material/trees/c71ad30d0b7271b70af39c5aa47d5bd6ad77005c/addon/modelview/ex-sortfiltertableviewhttp://

      you can retrieve from QTableView clicked(QModelIndex) signal, an use the model index to get the information you need.

      in SortedTableView I have done the next changes:

      • create a new slot void clicked(const QModelIndex &index);
      • made the connection, when clicked is performed to call the update method

      @connect(_tableView, SIGNAL(clicked(QModelIndex)), SLOT(clicked(QModelIndex)));@

      @#include <QtGui>

      #include "SortedTableView.h"

      SortedTableView::SortedTableView( QWidget *parent )
      : QWidget ( parent )
      , _filter ( new QSortFilterProxyModel() )
      {
      ...
      connect(_tableView, SIGNAL(clicked(QModelIndex)), SLOT(clicked(QModelIndex)));
      ...
      }

      void SortedTableView::clicked(const QModelIndex &index)
      {
      QVariant v = index.data();
      //just as a test, set the line filter with the value retrieved
      _lineEdit->setText(v.toString());
      }
      @

      regards,
      Dănuț

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        Thanks! I will see these examples.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved