填充QTableView的最后一个空列
在填充QTableView的最后一个空列,qt,qtableview,qheaderview,Qt,Qtableview,Qheaderview,在QTableView中,我需要最后一列(最右边)为空、可展开但不可移动。目标是使表不会突然结束(因为我对行使用了替换颜色)或向右扩展。在QHeaderView中有一个setFirstSectionMovable(bool);我需要为最后一部分做一些类似的事情,让其余部分可以移动。(换句话说:用空的不可移动的列填充表格的其余部分)。你知道怎么做吗 我确实在QHeaderView的子类中重写了mousePressEvent(),跳过了最后一节,但它仍然可以通过移动其他列来移动,我不知道如何防止这种
QTableView
中,我需要最后一列(最右边)为空、可展开但不可移动。目标是使表不会突然结束(因为我对行使用了替换颜色)或向右扩展。在QHeaderView
中有一个setFirstSectionMovable(bool)
;我需要为最后一部分做一些类似的事情,让其余部分可以移动。(换句话说:用空的不可移动的列填充表格的其余部分)。你知道怎么做吗
我确实在QHeaderView
的子类中重写了mousePressEvent()
,跳过了最后一节,但它仍然可以通过移动其他列来移动,我不知道如何防止这种情况。AMOQ:
Be HeaderView是QHeaderView的一个子类,具有
处理移动信号:
覆盖鼠标压力:
您是否尝试重新实现
moveSection()
?
setSectionsMovable(true);
setStretchLastSection(true);
connect(this, &QHeaderView::sectionMoved, [this](int, int, int newVisual) {
if(newVisual == count()-1) { moveSection(newVisual, newVisual-1); }
});
void HeaderView::mousePressEvent(QMouseEvent* event) {
int logicalIdx = logicalIndexAt(event->pos());
if(logicalIdx != count()-1) { QHeaderView::mousePressEvent(event); }
}