QLineEdit with mouse wheel: setModelData is called too late after commitData
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!
Code:
setFocusPolicy(Qt::WheelFocus);
}
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;
}
}
QLineMouseEdit *Editor = new QLineMouseEdit(parent);
connect(Editor, SIGNAL(changed()), this, SLOT(changed()));
return Editor;
}
qDebug() << "CModelTreeDelegate::setModelData"; // ??? sometimes too late ???
}
void CModelTreeDelegate::changed() {
QLineMouseEdit *Editor = qobject_cast<QLineMouseEdit *>(sender());
if (Editor) {
qDebug() << "CComboDelegate::changed emit commitData"; // ok!!
emit commitData(Editor);
}
}
Re: QLineEdit with mouse wheel: setModelData is called too late after commitData
It seems that the data you're dealing with is a decimal number. Why don't you use a QDoubleSpinBox instead of a QLineEdit.
If I properly understood what you want to achieve using a QDoubleSpinBox will solve your problem because it supports changing the value using the mouse wheel out of the box. To achieve the step to be done like you need it to be done I suggest overwriting void QAbstractSpinBox::stepBy(int steps).
Re: QLineEdit with mouse wheel: setModelData is called too late after commitData
@Infinity: your approach does really fit my situation much more!
But: still got update problems when I scroll the mouse too quickly.
Thanks anyway!
Re: QLineEdit with mouse wheel: setModelData is called too late after commitData
Quote:
still got update problems when I scroll the mouse too quickly
Maybe we are able to help if you post your code.
Re: QLineEdit with mouse wheel: setModelData is called too late after commitData
@Infinity: I definitly will post some code. I 'only' have to strip down the code to some short example.
Thanks for your help!