Selected Rows in QTableView, copy to QClipboard

后端 未结 12 611
别那么骄傲
别那么骄傲 2020-12-25 08:14

I have a SQLite-Database and I did it into a QSqlTableModel. To show the Database, I put that Model into a QTableView.

Now I want to create

12条回答
  •  -上瘾入骨i
    2020-12-25 08:46

    I finally got it, thanks.

    void Widget::copy() {
    
    QItemSelectionModel *selectionM = tableView->selectionModel();
    QModelIndexList selectionL = selectionM->selectedIndexes();
    
    selectionL.takeFirst(); // ID, not necessary
    QString *selectionS = new QString(model->data(selectionL.takeFirst()).toString());
    selectionS->append(", ");
    selectionS->append(model->data(selectionL.takeFirst()).toString());
    selectionS->append(", ");
    selectionS->append(model->data(selectionL.takeFirst()).toString());
    selectionS->append(", ");
    selectionS->append(model->data(selectionL.takeFirst()).toString());
    
    clipboard->setText(*selectionS);
    }
    

    and

    connect (tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(copy()));
    

提交回复
热议问题