[英]Change what column of QTreeView displays expand/collapse icon
Qt version 4.8.4 Qt版本4.8.4
I have a QTreeView that reflects a QAbstractItemModel-derived model. 我有一个QTreeView反映了QAbstractItemModel派生的模型。 The model provides data in multiple columns.
该模型在多列中提供数据。 The expand/collapse icon for a row of the view is always displayed in the cell that is in the column that has a logical index of zero, even if that column has been moved so that it has a visual index other than zero.
视图行的展开/折叠图标始终显示在逻辑索引为零的列中的单元格中,即使该列已移动以使其视觉索引不为零也是如此。
Is QTreeView compelled to always draw the expand/collapse icon in logical column zero? QTreeView是否必须总是在逻辑列零中绘制展开/折叠图标? Can that be customized, either via the QTreeView or the model?
是否可以通过QTreeView或模型自定义?
The expand/collapse icon, along with all the other tree branching lines, is indeed compelled to always draw in logical column zero. 实际上,展开/折叠图标以及所有其他树状分支线确实必须始终绘制在逻辑列零中。 In Qt/4.8.4/src/gui/itemviews/qtreeview.cpp, in the
QTreeView::drawRow()
method, it is hardcoded to only call QTreeView::drawBranches()
if the headerSection
(which contains the logical index of the column) is zero. 在Qt / 4.8.4 / src / gui / itemviews / qtreeview.cpp中,在
QTreeView::drawRow()
方法中,如果headerSection
(包含其中的逻辑索引QTreeView::drawBranches()
仅调用QTreeView::drawBranches()
硬编码。列)为零。
void QTreeView::drawRow( QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
...
for ( int currentLogicalSection = 0; currentLogicalSection < logicalIndices.count(); ++currentLogicalSection )
{
int headerSection = logicalIndices.at(currentLogicalSection);
...
// If the zeroeth logical column, ...
if ( headerSection == 0 )
{
...
// ... draw tree branches and stuff.
drawBranches(painter, branches, index);
}
else
{
...
}
...
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.