我在应用程序中有一个QTableView
宽度QAbstractTableModel
,我想让每列具有不同的宽度,并带有调整大小选项ui->tableView->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch);
在我的模型中,我这样做:
class rangeModel : public QAbstractTableModel {
//other code .......
QVariant rangeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal)
return QVariant();
if (role != Qt::DisplayRole && role != Qt::SizeHintRole)
return QVariant();
if(role == Qt::SizeHintRole)
{
switch (section) {
case 0: return QSize(58, 20);
case 1: return QSize(58, 20);
case 2: return QSize(58, 20);
case 3: return QSize(228, 20);
}
}
switch (section) {
case 0: return "PREFIXMIN";
case 1: return "PREFIXMAX";
case 2: return "VALUE";
case 3: return "PROGRESS BAR";
default: return QVariant();
}
}
所以我希望我的行的大小不同,但它不会发生,视图由于某种原因被忽略,而且即使没有选项QSizeHint
它也不起作用。QHeaderView::Stretch
如何使列和标题的大小不同?