Selected Rows in QTableView, copy to QClipboard

后端 未结 12 656
别那么骄傲
别那么骄傲 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条回答
  •  臣服心动
    2020-12-25 08:39

    I can't help but notice that you can simplify your code using a foreach() construct and the QStringList class, which has a convenient join() function.

    void Widget::copy()
    {
       QStringList list ;
       foreach ( const QModelIndex& index, tableView->selectedIndexes() )
       {
          list << index.data() ;
       }
    
       clipboard->setText( list.join( ", " ) ) ;
    }
    

提交回复
热议问题