一. 关于十字形高亮的解决方法:
使用选择视图QItemSelectionModel
.
//将第row行与第column设置为高亮
void Widget::setHighlight(int row,int column)
{
QItemSelectionModel *selectionModel = tableWidget->selectionModel();
QModelIndex top = tableWidget->model()->index(row, column, QModelIndex());
QModelIndex bottom = tableWidget->model()->index(row, column, QModelIndex());
QItemSelection selection(top, bottom);
selectionModel->select(selection, QItemSelectionModel::Select|
QItemSelectionModel::Rows|QItemSelectionModel::Columns);
}
其中
QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
Flags可以进行位操作。
参考资料:http://www.aichengxu.com/jiagou/6197787.htm
二. 关于将QtableWidget 中QComboBox的问题。
一开始自己的想法跑偏了(每点击单元格则生成QComboBox,第二次点击则将第一次的那个隐藏掉),如果这样的话,一个8行4列的table 最多需要实例化32个QComboBox,内存的问题就很严重了,而且怎么隐藏掉第一个也不好处理。(隐藏掉其实蛮好处理的,用成员