how to get selected rows in QTableView

后端 未结 3 682
小鲜肉
小鲜肉 2020-12-07 20:18

After watching many threads about getting selected rows numbers, I am really confused.

How do you get ROW numbers in QTableView using QStandardIte

相关标签:
3条回答
  • 2020-12-07 20:53

    The method selectionModel() return a QItemSelectionModel.

    You can use QItemSelectionModel class to check/change/other selection(s)

    Example:

    QItemSelectionModel *select = table->selectionModel();
    
    select->hasSelection() //check if has selection
    select->selectedRows() // return selected row(s)
    select->selectedColumns() // return selected column(s)
    ...
    
    0 讨论(0)
  • 2020-12-07 21:08

    Check selectedRows method of the QItemSelectionModel Class .

    QModelIndexList selection = yourTableView->selectionModel()->selectedRows();
    
    // Multiple rows can be selected
    for(int i=0; i< selection.count(); i++)
    {
        QModelIndex index = selection.at(i);
        qDebug() << index.row();
    }
    
    0 讨论(0)
  • 2020-12-07 21:11

    try:

    QModelIndexList indexList = yourTableView->selectionModel()->selectedIndexes();
    int row;
    foreach (QModelIndex index, indexList) {
        row = index.row();
        ....
    }
    
    0 讨论(0)
提交回复
热议问题