for(int i=0; i<6; ++i) { QTreeWidgetItem* item = new QTreeWidgetItem(ui.treeWidget); item->setText(0, QString::number(i+1) ); // channel number item->setTextAlignment(0, Qt::AlignCenter); item->setText(1, _Stats[0]); // default status0 item->setFlags(Qt::ItemIsEditable|Qt::ItemIsEnabled); } StatDelegate* sg = new StatDelegate(ui.treeWidget); ui.treeWidget->setItemDelegateForColumn(1, sg);
C++ (Qt)class NoEditorDelegate : public QStyledItemDelegate{public: NoEditorDelegate(QObject *parent) : QStyledItemDelegate(parent) {} virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(parent) Q_UNUSED(option) Q_UNUSED(index) return 0; }}; ... ui->tree->setItemDelegateForColumn(1, new NoEditorDelegate(ui->tree));
for(int i=0; i<6; ++i) { QTreeWidgetItem* item = new QTreeWidgetItem(ui.treeWidget); item->setText(0, QString::number(i+1) ); // channel number item->setTextAlignment(0, Qt::AlignCenter); item->setText(1, _Stats[0]); // default status0 item->setFlags(Qt::ItemIsEnabled); } StatDelegate* sg = new StatDelegate(ui.treeWidget); ui.treeWidget->setItemDelegateForColumn(1, sg);