How to get complete row from qtable widget?



  • Im performing search operation on a tablewidget.(using search key)
    Highlighted found key in the table widget.
    Now i want to update the table, which contains only those rows which has search key.

    Now i already highlighted the found search key, but i'm unable to fetch whole row which contains the search key.
    Please tell me how can i get that particular row, which contain that search key?
    my code is as follows..
    @
    QString SearchKey=ui->lineEdit_key->text();
    QList<QTableWidgetItem *> LTempTable =temp->findItems(SearchKey,Qt::MatchExactly);

     cout<<"the matched count:"<<LTempTable.count()<<endl;
     foreach(rowPtr,LTempTable)
     {
        rowPtr->setBackground(Qt::red);
        int rowNo=temp->row(rowPtr);
        cout<<"THE ROW NUMBER IS:"<<rowNo<<endl;            <-----getting row number but how can i get complete row?
     
        }
    

    }
    @



  • By "complete row" you mean all the items in that row?
    In that case, can you not simply loop over the columns, and get the item in each column, with the given row number?
    Or did I misunderstand something?



  • [quote author="ludde" date="1326108835"]By "complete row" you mean all the items in that row?
    In that case, can you not simply loop over the columns, and get the item in each column, with the given row number?
    Or did I misunderstand something?[/quote]

    Ya ludde exactly....
    I want all the items of that row and want to insert that row into some other table....
    How can i do that?



  • Well, you have rowNo and a pointer to your widget - temp (?). To copy all the items in the row, just do something like:
    @
    for (int c = 0; c < temp->columnCount(); ++c)
    copyItem(temp->item(rowNo, c));
    @
    How you copy the individual items into the other table is up to you, I guess.



  • You're missing a basic principle of the model-view architecture here. Instead of copying around rows, considder changing your setup to something like this:

    Replace your QTableWidget by a [[doc:QTableView]]

    put your data in a model. That could be a [[doc:QStandardItemModel]] which has an API that is very similar to QTableWidget, but you could also use another type of model, perhaps something based on [[doc:QAbstractTableModel]].

    to highlight the rows, you insert a proxy model based on [[doc:QIdentityProxyModel]] between your model and the view

    to display only the highlighted items in a seconds view, you create a new QTableView somewhere, and make that one display the same basic model, but this time filtered through a [[doc:QSortFilterProxyModel]].

    In this way, you have the source data only once, and you simply filter and display it in a different way.



  • Ok thanks all..:)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.