QT QTableWidget中实现整行选中和禁止编辑单元格

 

整行选中:

ui.tableWidget->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为,以行为单位
ui.tableWidget->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行

QT QTableWidget中实现整行选中和禁止编辑单元格_第1张图片

禁止编辑:

ui.tableWidget->setEditTriggers ( QAbstractItemView::NoEditTriggers );

关于编辑状态的文档:

Constant Value Description
QAbstractItemView::NoEditTriggers 0 No editing possible.
QAbstractItemView::CurrentChanged 1 Editing start whenever current item changes.
QAbstractItemView::DoubleClicked 2 Editing starts when an item is double clicked.
QAbstractItemView::SelectedClicked 4 Editing starts when clicking on an already selected item.
QAbstractItemView::EditKeyPressed 8 Editing starts when the platform edit key has been pressed over an item.
QAbstractItemView::AnyKeyPressed 16 Editing starts when any key is pressed over an item.
QAbstractItemView::AllEditTriggers 31 Editing starts for all above actions.

你可能感兴趣的:(QT QTableWidget中实现整行选中和禁止编辑单元格)