English 中文(简体)
在QTreeWidget的Raise 和较低的QTreeWidgetItem?
原标题:Raise and lower QTreeWidgetItem in a QTreeWidget?

问题表明,你如何在树林植被中提出和降低[改变]QTreeWidgetItems的位置,

最佳回答

我认为,你需要使用模范物体才能操纵项目位置(如果你想要这样做的话)。 请举一个例子:将抽象模式的第一个项目移至底。

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);

一旦项目在模型中移入,您的树木概貌植被应相应更新。

如有必要改变您的树木情况表所示项目的规模:http://qt.nokia.com/doc/4.6/qetteditemdelegate.html” 方法

希望这一帮助,

问题回答

I found serge s solution to be quite complicated as well for a simple move up / move down. There s actually a quite easier solution to this issue since you re using QTreeWidget :

QTreeWidgetItem* item = your_qtreewidget->currentItem();
int              row  = your_qtreewidget->currentIndex().row();

if (item && row > 0)
{
    your_qtreewidget->takeTopLevelItem(row);
    your_qtreewidget->insertTopLevelItem(row - 1, item);
    your_qtreewidget->setCurrentItem(item);
}

在这里,你有一项法典,将一个项目移至上。 从这一点来看,你们应当能够找到如何在任何时候放下它!





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签