[Solved]Can QTreeWidget Really be edited?



  • Hi,everyone.

    I'm now puzzled about QTreeWidget.

    The doc says, QTreeWidget inherits from QAbstractItemView.I want the QTreeWidgetItem in a QTreeWidget to be editable when users double click the mouse on the item.

    I use
    @(QTreeWidget*)someTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked);@

    But When I run the program,double click seems of no use.The item is still read-only and can't be modified.

    Does anyone solve this problem before? Is the only way to use Model/View menthod & QTreeView instead?


    I'm sorry to trouble you.But I just found the key to the problem.

    It is about the QTreeWidgetItem.When you want to modify a item in QTreeWidget or others, set the edittriggers is not enough.

    Every item to be added in the widget must set theis flags first.

    @(QTreeWidgetItem*)someItem->setFlags(Qt::ItemIsEditable|Qt::ItemIsEnabled);@

    And that may work.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.