Making only one column of a QTreeWidgetItem editable

后端 未结 10 1141
无人共我
无人共我 2020-12-06 04:18

I have a QTreeWidgetItem with two columns of data, is there any way to make only the second column editable? When I do the following:

QTreeWidge         


        
10条回答
  •  清歌不尽
    2020-12-06 05:01

    You can make only certain columns in a QTreeWidget editable using a workaround:

    1) Set the editTriggers property of the QTreeWidget to NoEditTriggers

    2) On inserting items, set the Qt:ItemIsEditable flag of the QTreeWidgetItem object

    3) Connect the following slot to the "itemDoubleClicked" signal of the QTreeWidget object:

    void MainWindow::onTreeWidgetItemDoubleClicked(QTreeWidgetItem * item, int column)
    {
        if (isEditable(column)) {
            ui.treeWidget->editItem(item, column);
        }
    }
    

    where "isEditable" is a function you wrote that returns true for editable columns and false for non-editable columns.

提交回复
热议问题