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

 
转自: http://hi.baidu.com/buptyoyo/blog/item/6a0c573a41d4332fb8998f93.html

整行选中:

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中实现整行选中和禁止编辑单元格)