没有人帮助,自己动手。花了8个小时,终于功成。
1、在头文件中定义一个QHeaderView类型变量,及定义将要用到的槽
QHeaderView *header;
void myRowResized(int logindex, int oldheight, int newheight);
2、在其构建函数中,对变量赋值,建立相应连接
header = this->verticalHeader();
connect(header, SIGNAL(sectionResized(int,int,int)), this, SLOT(myRowResized(int,int,int)));
3、建立槽函数
void myTableWidget::myRowResized(int logindex, int oldheight, int newheight)
{
disconnect(header, SIGNAL(sectionResized(int,int,int)), this, SLOT(myRowResized(int,int,int)));
QTableWidgetSelectionRange range ;
QList<QTableWidgetSelectionRange> ranges = selectedRanges() ;
if (!ranges.isEmpty()) { //可能分几块不连续选择区
range = ranges.first(); //只对第一块操作
int add = newheight - oldheight;
for (int i= range.topRow(); i<=range.bottomRow(); ++i){
if (i != logindex) {
int height = this->rowHeight(i) + add;
this->setRowHeight(i, height);
}
}
}
connect(header, SIGNAL(sectionResized(int,int,int)), this, SLOT(myRowResized(int,int,int)));
}
4、测试成功