如果使用QTableWidget的时候,不设置任何属性,那么当单击的时候,只选中当前的单元格
如果想要设置单行选择,那么调用setSelectionBehavior接口,设置QAbstractItemView::SelectRows的属性
tableWidget_code_sure->setSelectionBehavior(QAbstractItemView::SelectRows); //选中单元格,行还是列
运行程序之后,可以看到单击之后,选中的是当前行,而不是单元格
如果表格不需要支持Ctrl、Shift、 Ctrl+A等操作方法,那么可以调用接口setSelectionMode设置属性为QAbstractItemView::SingleSelection
tableWidget->setSelectionMode(QAbstractItemView::SingleSelection) //设置单行模式
如果想要表格支持多选模式,比如Ctrl、Shift、 Ctrl+A、鼠标左键按下滑动多选等操作方法,那么可以调用接口setSelectionMode设置属性为QAbstractItemView::ExtendedSelection
//设置单选,多选,扩展选择
tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); //多选模式