我想隐藏显示为最后一列的预览小部件,即使它没有子项也是如此。我在互联网上到处查看,无数用户不希望预览小部件始终添加为最后一列。
- QColumnView is rolled to empty column
- Qt: is it possible to turn off previewWidget in QColumnView?
- Is it possible to remove the preview widget from a qt QColumnView?
- http://www.qtcentre.org/threads/59917-Columnview-removing-final-column
- http://www.qtcentre.org/threads/22566-How-to-turn-off-this-annoying-feature-of-QColumnView
更可悲的是,到目前为止[从2010年开始]还没有提供解决方案。有什么办法可以摆脱这种烦人的行为吗?如果没有,Qt 开发人员不应该至少在 Qt5 中提供此选项吗?如果我错过了什么,请告诉我。
注意:我已经尝试了可能的建议的解决方案,但没有一个有效
- 将列宽设置为 0 - 失败
- createColumn 返回 False - 显示预览小部件时根本不会调用 createColumn
最佳答案
没有办法做到这一点。在 QColumnViewPrivate::createColumn()
的 qcolumnview.cpp
中,您有(评论是我的):
if (model->hasChildren(index)) { // Create column when there are children to display
view = q->createColumn(index);
q->connect(view, SIGNAL(clicked(QModelIndex)),
q, SLOT(_q_clicked(QModelIndex)));
} else { // Create column when there are no more children => the column will show the preview widget
if (!previewColumn)
setPreviewWidget(new QWidget(q)); // Indirectly create previewColumn
view = previewColumn;
view->setMinimumWidth(qMax(view->minimumWidth(), previewWidget->minimumWidth()));
}
如果您想更改 QColumnView 的行为,以便预览小部件不总是显示,您必须通过在 Qt 代码中自行修复它并推送到 Qt git 存储库来做出贡献,或者在 Qt bug tracker 中创建建议并等待好心人修复它。
关于qt - 在 QColumnView 中隐藏预览小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42408736/