ctgrund
11th February 2014, 21:27
Hi,
In a tree view I would like a QLineEdit where I can change the value with the mouse wheel.
The following idea works fine when I slowly scroll the wheel. But when I faster scroll the wheel sometimes I am missing a call to setModelData. This function is then only called when I click somewhere else in the tree view.
Thank you!
QLineMouseEdit::QLineMouseEdit(QWidget *aParent): QLineEdit(aParent) {
setFocusPolicy(Qt::WheelFocus);
}
void QLineMouseEdit::wheelEvent(QWheelEvent *aEvent) {
double LinearChange = 1;
if (LinearChange!=0) {
double Delta = aEvent->delta();
double OldValue = text().toDouble();
double NewValue = OldValue + Delta/120*LinearChange;
setText(QString::number(NewValue));
qDebug() << "";
qDebug() << "wheelEvent emit changed" << NewValue; // ok!!
emit changed();
return;
}
}
QWidget *CModelTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
QLineMouseEdit *Editor = new QLineMouseEdit(parent);
connect(Editor, SIGNAL(changed()), this, SLOT(changed()));
return Editor;
}
void CModelTreeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
qDebug() << "CModelTreeDelegate::setModelData"; // ??? sometimes too late ???
QItemDelegate::setModelData(editor, model, index);
}
void CModelTreeDelegate::changed() {
QLineMouseEdit *Editor = qobject_cast<QLineMouseEdit *>(sender());
if (Editor) {
qDebug() << "CComboDelegate::changed emit commitData"; // ok!!
emit commitData(Editor);
}
}
In a tree view I would like a QLineEdit where I can change the value with the mouse wheel.
The following idea works fine when I slowly scroll the wheel. But when I faster scroll the wheel sometimes I am missing a call to setModelData. This function is then only called when I click somewhere else in the tree view.
Thank you!
QLineMouseEdit::QLineMouseEdit(QWidget *aParent): QLineEdit(aParent) {
setFocusPolicy(Qt::WheelFocus);
}
void QLineMouseEdit::wheelEvent(QWheelEvent *aEvent) {
double LinearChange = 1;
if (LinearChange!=0) {
double Delta = aEvent->delta();
double OldValue = text().toDouble();
double NewValue = OldValue + Delta/120*LinearChange;
setText(QString::number(NewValue));
qDebug() << "";
qDebug() << "wheelEvent emit changed" << NewValue; // ok!!
emit changed();
return;
}
}
QWidget *CModelTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
QLineMouseEdit *Editor = new QLineMouseEdit(parent);
connect(Editor, SIGNAL(changed()), this, SLOT(changed()));
return Editor;
}
void CModelTreeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
qDebug() << "CModelTreeDelegate::setModelData"; // ??? sometimes too late ???
QItemDelegate::setModelData(editor, model, index);
}
void CModelTreeDelegate::changed() {
QLineMouseEdit *Editor = qobject_cast<QLineMouseEdit *>(sender());
if (Editor) {
qDebug() << "CComboDelegate::changed emit commitData"; // ok!!
emit commitData(Editor);
}
}