python - 在 QTreeWidget 中升高和降低 QTreeWidgetItem?

标签 python qt pyqt qtreewidget

问题说明了你如何在 QtreeWidget 中升高和降低 [改变] QTreeWidget 项目的位置,

最佳答案

我相信您需要使用模型对象才能操纵元素的位置(如果这是您想要做的)。请检查以下示例;它将抽象模型的第一项移动到底部。

QAbstractItemModel* model = your_tree_view->model();

QModelIndex index0 = model->index(0, 0);
QMap<int, QVariant> data = model->itemData(index0);
// check siblings of the item; should be restored later
model->removeRow(0);

int rowCount = model->rowCount();
model->insertRow(rowCount);
QModelIndex index1 = model->index(rowCount, 0);
model->setItemData(index1, data);

一旦项目在模型中移动,您的 TreeView 小部件应该相应地自行更新

如果您需要更改 TreeView 显示的项目的大小,请安装 item delegate并覆盖它的 sizeHint方法

希望这对你有帮助,问候

关于python - 在 QTreeWidget 中升高和降低 QTreeWidgetItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2035932/

相关文章:

python - 基于 peewee 查询的过滤列表

qt - 在 Qt Creator 中将 TagLib 库添加到 Linux Qt 项目?

python - 用户调整 PyQt 小部件的大小

python - 大写连字符名称

python - 在 Windows 上执行脚本时隐藏控制台

c++ - 自定义小部件上 float 类型的 Q_PROPERTY 未出现在属性编辑器中

c++ - Qt 和 Mac OS X 下注册全局热键

python - 将 QHBoxLayout 的每个小部件对齐到顶部

python - PyQt错误 “QProcess: Destroyed while process is still running”

python - 如何检查数据框中是否存在具有相同值组合的行?