代码是从一个完整的工程里面抽取出来的,所以有些地方可以根据需要修改,QTableView/QTableWidget都能适用
我们在特定的需求下(日历日程的)需要连续选中的一些Item,而Qt默认的只能选中N行或者N列,如图
下面看一下处理过后的效果图:
接下来就是代码了,很简单的以后工程,后面会放工程代码的链接
1、选中firstIndex到lastIndex中间的所有item
void W_TableScheduleMonth::selectIndexs(QModelIndex firstIndex , QModelIndex lastIndex)
{
W_TableScheduleMonthItem * firstItemWidget =this->getWItem(firstIndex.row() , firstIndex.column());
W_TableScheduleMonthItem * lastItemWidget = this->getWItem(lastIndex.row() , lastIndex.column());
if(firstItemWidget && lastItemWidget){
QList<W_TableScheduleMonthItem*> lsItem = m_mapItem.values()