Qt-interest Archive, February 2008
QStandardItem ignoring setEditable() in Qt 4.3.3
Message 1 in thread
hi,
i have an application which was previously compiled against the Qt 4.3.0
libraries, but which i just linked to the 4.3.3 libraries, and for some
unexplained reason, the QStandardItems on which i have set
setEditable(false) are now editable. i'm trying to create a simple
example application which exhibits the same behavior, but have so far
been unsuccessful.
i looked through the task tracker and didn't see anything that seemed to
be too closely related to my problem, so i thought i'd see if anyone
else out there might be running into the same problem.
jeff.
--
[ signature omitted ]
Message 2 in thread
Jeff Fisher wrote:
> hi,
>
> i have an application which was previously compiled against the Qt 4.3.0
> libraries, but which i just linked to the 4.3.3 libraries, and for some
> unexplained reason, the QStandardItems on which i have set
> setEditable(false) are now editable. i'm trying to create a simple
> example application which exhibits the same behavior, but have so far
> been unsuccessful.
>
> i looked through the task tracker and didn't see anything that seemed to
> be too closely related to my problem, so i thought i'd see if anyone
> else out there might be running into the same problem.
>
>
> jeff.
after giving up on this for a while, i finally came back to it. i
haven't been completely able to track down what's going on here, but it
looks like the problem is actually within QTreeView, and more
specifically it looks like the behavior has changed with regard to
column spanning. Whereas in 4.3.0 all columns spanned by an item would
share the same editable property, in 4.3.3 they do not.
the following is an example of what i'm talking about - try compiling it
against both Qt/4.3.3 and Qt/4.3.0:
////////////////////
// qsi.h:
//
#ifndef _QSI_H
#define _QSI_H
#include <QTreeView>
#include <QStandardItemModel>
class TreeView : public QTreeView
{
Q_OBJECT
public:
TreeView(QStandardItemModel *pModel) : QTreeView(), m(pModel)
{
setModel(m);
}
public slots:
void activated(const QModelIndex &index)
{
edit(index.sibling(index.row(), 1));
}
void selected(const QItemSelection &n, const QItemSelection &o)
{
if (!n.isEmpty())
{
// Get the selected index
QModelIndex index = n.indexes().first();
// Get the index of the adjacent cell
QModelIndex sibling = index.sibling(index.row(), 1);
// Open the adjacent cell for editing
edit(sibling);
}
}
protected:
QStandardItemModel *m;
};
#endif
////////////////////
// qsi.cpp
//
#include <QApplication>
#include <QItemDelegate>
#include "qsi.h"
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QStandardItemModel *model = new QStandardItemModel;
model->setHorizontalHeaderLabels(QStringList() << "A" << "B");
TreeView *tv = new TreeView(model);
tv->setItemDelegate(new QItemDelegate);
QObject::connect(tv, SIGNAL(activated(QModelIndex)),
tv, SLOT(activated(QModelIndex)));
QObject::connect(tv->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
tv, SLOT(selected(QItemSelection, QItemSelection)));
QStandardItem *p = new QStandardItem("0");
p->setEditable(false);
model->invisibleRootItem()->setChild(0, 0, p);
QModelIndex idx = model->invisibleRootItem()->index();
tv->setFirstColumnSpanned(0, idx, true);
tv->show();
return a.exec();
}
--
[ signature omitted ]