Skip to content

Commit

Permalink
OWCreateInstance: Disable scrolling to change value
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Oct 26, 2020
1 parent 0159778 commit f375393
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Orange/widgets/data/owcreateinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from AnyQt.QtCore import Qt, QSortFilterProxyModel, QSize, QDateTime, \
QModelIndex, Signal, QPoint, QRect
QModelIndex, Signal, QPoint, QRect, QEvent
from AnyQt.QtGui import QStandardItemModel, QStandardItem, QIcon, QPainter
from AnyQt.QtWidgets import QLineEdit, QTableView, QSlider, \
QComboBox, QStyledItemDelegate, QWidget, QDateTimeEdit, QHBoxLayout, \
Expand Down Expand Up @@ -163,6 +163,9 @@ def deselect():
# self._spin.lineEdit().selectionChanged only for editor creation.
self._spin.lineEdit().selectionChanged.connect(deselect)

self._slider.installEventFilter(self)
self._spin.installEventFilter(self)

@property
def value(self) -> float:
return self.__round_value(self._value)
Expand Down Expand Up @@ -195,6 +198,12 @@ def __map_to_slider(self, value: float) -> int:
def __map_from_slider(self, value: int) -> float:
return value * 10 ** (-self._n_decimals)

def eventFilter(self, obj: Union[QSlider, QDoubleSpinBox], event: QEvent) \
-> bool:
if event.type() == QEvent.Wheel:
return True
return super().eventFilter(obj, event)


class StringVariableEditor(VariableEditor):
value_changed = Signal()
Expand Down Expand Up @@ -252,6 +261,8 @@ def sizeHint(self) -> QSize:
self.layout().addWidget(self._edit)
self.setFocusProxy(self._edit)

self._edit.installEventFilter(self)

@property
def value(self) -> float:
return self._value
Expand All @@ -273,6 +284,11 @@ def __map_to_datetime(self, value: float) -> QDateTime:
return QDateTime.fromString(self._variable.repr_val(value),
self._format)

def eventFilter(self, obj: QDateTimeEdit, event: QEvent) -> bool:
if event.type() == QEvent.Wheel:
return True
return super().eventFilter(obj, event)


class VariableDelegate(QStyledItemDelegate):
def paint(self, painter: QPainter, option: QStyleOptionViewItem,
Expand Down

0 comments on commit f375393

Please sign in to comment.