View Full Version : QTreeView rows editable
Pesho
13th September 2007, 12:15
Hello,
How can I disable the editable rows in QTreeView, I'm using the standard model "QStandardItemModel"
http://useqt.hit.bg/QTreeView.jpg
Thanks.
jpn
13th September 2007, 12:26
Use QStandardItem::setFlags() to remove Qt::ItemIsEditable which is turned on by default:
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
Pesho
13th September 2007, 12:37
QAbstractItemModel *pModel = new QStandardItemModel(parent);
I got this error: error C2039: 'setFlags' : is not a member of 'QAbstractItemModel'
How I'm supoused to use QStandardItem with QAbstractItemModel?
jpn
13th September 2007, 12:42
So, you're not using QStandardItems to fill QStandardItemModel? Alternative approach is to reimplement QAbstractItemModel::flags() and make sure no Qt::ItemIsEditable is returned:
Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex& index) const
{
return (QStandardItemModel::flags(index) & ~Qt::ItemIsEditable);
}
Pesho
13th September 2007, 13:15
Thank you :)
My second question is: how to remove the dotted border in the selected row on the selected column like the picture below:
http://useqt.hit.bg/QTreeView2.jpg
jpn
13th September 2007, 13:19
If you want the focus rect to appear around the whole row instead, use QAbstractItemView::setSelectionBehavior() (http://doc.trolltech.com/latest/qabstractitemview.html#selectionBehavior-prop) and QAbstractItemView::SelectRows.
If you don't want the widget to receive focus at all, use QWidget::setFocusPolicy() (http://doc.trolltech.com/latest/qwidget.html#focusPolicy-prop) and Qt::NoFocus.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.