2

I'm using a QTreeView with a QStandardItemModel and I'm trying to figure out how to move items up and down the tree using buttons . I can do drag and drop no problem, but what I would like to do is have some buttons associated with "move up" and "move down" functions. I just cant find anything on the subject. There seems to be a "moveRow()" function for the model object, but I cant find any documentation on it so I'm not sure if its what I need. Any information you could give to point me in the right direction would be greatly appreciated!

PS Here are my QT Creator stats: Qt Creator 2.6.2 Based on Qt 5.0.1 (64 bit)

4

1 回答 1

3

你的预感是正确的。moveRow()是要调用的正确函数。

要在一个父对象中移动项目(毕竟它是一棵树),你会这样做moveRow(parent, index.row(), parent, index.row() + delta),其中delta设置为 1 或 -1,具体取决于你是向下移动还是向上移动。

如果您想允许项目在父项之间移动,您将需要额外的逻辑来确定目标父项是否会移过其父项。

请注意,如果移动按钮与要移动的项目分开,则被认为是糟糕的设计。您的委托应在其行中为每个项目显示向上和向下箭头,以便您可以一键移动内容。当存在连续选择时,代表应合并向上/向下箭头以覆盖所有项目。When the selection is non-contiguous, the up/down arrows should disappear.

使用单独的按钮,您需要单击两次:首先选择项目,然后单击向上/向下。从用户体验的角度来看,这 很糟糕。

于 2013-09-06T17:26:40.560 回答