qt/ledset/table.cpp

19 lines
918 B
C++
Raw Normal View History

2022-08-25 18:43:03 +08:00
#include "table.h"
int Table::sizeHintForColumn(int column) const {
auto item = horizontalHeaderItem(column);
if(!item) return QTableWidget::sizeHintForColumn(column);
int width = item->data(0x99).toInt();
if(!width) return QTableWidget::sizeHintForColumn(column);
auto header = horizontalHeader();
if(header->sectionResizeMode(column)!=QHeaderView::ResizeToContents) return QTableWidget::sizeHintForColumn(column);
int colCnt = columnCount();
int remainWidth = header->width(), stretchWidth = width;
for(int cc=0; cc<colCnt; cc++) if(cc!=column && (item = horizontalHeaderItem(cc))) {
if(header->sectionResizeMode(cc)==QHeaderView::ResizeToContents) stretchWidth += item->data(0x99).toInt();
else remainWidth -= item->data(0x99).toInt();
}
if(remainWidth<=0) return QTableWidget::sizeHintForColumn(column);
return width * remainWidth / stretchWidth;
}