Please do not edit a question to something completely different after it has already been answered.
You can validate items like this:
{
public:
QWidget* createEditor
(QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
if (QLineEdit* lineEdit
= dynamic_cast<QLineEdit
*>
(editor
)) {
// check column in question from index.column() if needed
// lineEdit->setValidator(...);
}
return editor;
}
};
// usage:
treeWidget->setItemDelegate(new MyItemDelegate(treeWidget));
class MyItemDelegate : public QItemDelegate
{
public:
MyItemDelegate(QObject* parent = 0) : QItemDelegate(parent) {}
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QWidget* editor = QItemDelegate::createEditor(parent, option, index);
if (QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor))
{
// check column in question from index.column() if needed
// lineEdit->setValidator(...);
}
return editor;
}
};
// usage:
treeWidget->setItemDelegate(new MyItemDelegate(treeWidget));
To copy to clipboard, switch view to plain text mode
Bookmarks