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!

Qt Code:
  1. QLineMouseEdit::QLineMouseEdit(QWidget *aParent): QLineEdit(aParent) {
  2. setFocusPolicy(Qt::WheelFocus);
  3. }
  4.  
  5. void QLineMouseEdit::wheelEvent(QWheelEvent *aEvent) {
  6. double LinearChange = 1;
  7. if (LinearChange!=0) {
  8. double Delta = aEvent->delta();
  9. double OldValue = text().toDouble();
  10. double NewValue = OldValue + Delta/120*LinearChange;
  11. setText(QString::number(NewValue));
  12. qDebug() << "";
  13. qDebug() << "wheelEvent emit changed" << NewValue; // ok!!
  14. emit changed();
  15. return;
  16. }
  17. }
  18.  
  19. QWidget *CModelTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
  20. QLineMouseEdit *Editor = new QLineMouseEdit(parent);
  21. connect(Editor, SIGNAL(changed()), this, SLOT(changed()));
  22. return Editor;
  23. }
  24.  
  25. void CModelTreeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
  26. qDebug() << "CModelTreeDelegate::setModelData"; // ??? sometimes too late ???
  27. QItemDelegate::setModelData(editor, model, index);
  28. }
  29.  
  30. void CModelTreeDelegate::changed() {
  31. QLineMouseEdit *Editor = qobject_cast<QLineMouseEdit *>(sender());
  32. if (Editor) {
  33. qDebug() << "CComboDelegate::changed emit commitData"; // ok!!
  34. emit commitData(Editor);
  35. }
  36. }
To copy to clipboard, switch view to plain text mode