Repository: biolab/orange3

Issue:
Predictions: wrong colors in inactive state
**What's wrong?**

Selection background is black even when the widget has no keyboard focus.

**How can we reproduce the problem?** 

Open the widget and unfocus it.

This happens because the widget's table is composed of two tables. Only one can have focus, but both pretend to have it, otherwise one would have a grey selection. They do so by setting the state to active and has focus without checking whether the widget itself has focus or not.


Discussion:

Resolving patch:
diff --git a/Orange/widgets/data/owfeaturestatistics.py b/Orange/widgets/data/owfeaturestatistics.py
--- a/Orange/widgets/data/owfeaturestatistics.py
+++ b/Orange/widgets/data/owfeaturestatistics.py
@@ -708,7 +708,7 @@ def paint(self, painter, option, index):
         super().paint(painter, option, index)
 
 
-class DistributionDelegate(QStyledItemDelegate):
+class DistributionDelegate(NoFocusRectDelegate):
     def paint(self, painter, option, index):
         # type: (QPainter, QStyleOptionViewItem, QModelIndex) -> None
         scene = index.data(Qt.DisplayRole)  # type: Optional[QGraphicsScene]
@@ -716,14 +716,6 @@ def paint(self, painter, option, index):
             return super().paint(painter, option, index)
 
         painter.setRenderHint(QPainter.Antialiasing)
-
-        if option.state & QStyle.State_Selected:
-            background_color = option.palette.highlight()
-        else:
-            background_color = index.data(Qt.BackgroundRole)
-        if background_color is not None:
-            scene.setBackgroundBrush(background_color)
-
         scene.render(painter, target=QRectF(option.rect), mode=Qt.IgnoreAspectRatio)
 
         # pylint complains about inconsistent return statements
diff --git a/Orange/widgets/evaluate/owpredictions.py b/Orange/widgets/evaluate/owpredictions.py
--- a/Orange/widgets/evaluate/owpredictions.py
+++ b/Orange/widgets/evaluate/owpredictions.py
@@ -33,7 +33,7 @@
 from Orange.widgets.utils.sql import check_sql_input
 from Orange.widgets.utils.state_summary import format_summary_details
 from Orange.widgets.utils.colorpalettes import LimitedDiscretePalette
-from Orange.widgets.utils.itemdelegates import DataDelegate, TableDataDelegate
+from Orange.widgets.utils.itemdelegates import TableDataDelegate
 
 # Input slot for the Predictors channel
 PredictorSlot = namedtuple(
@@ -686,16 +686,20 @@ def showEvent(self, event):
         QTimer.singleShot(0, self._update_splitter)
 
 
-class DataItemDelegate(TableDataDelegate):
+class ItemDelegate(TableDataDelegate):
     def initStyleOption(self, option, index):
         super().initStyleOption(option, index)
         if self.parent().selectionModel().isSelected(index):
-            option.state |= QStyle.State_Selected \
-                            | QStyle.State_HasFocus \
-                            | QStyle.State_Active
+            option.state |= QStyle.State_Selected
+        if self.parent().window().isActiveWindow():
+            option.state |= QStyle.State_Active | QStyle.State_HasFocus
 
 
-class PredictionsItemDelegate(DataDelegate):
+class DataItemDelegate(ItemDelegate):
+    pass
+
+
+class PredictionsItemDelegate(ItemDelegate):
     """
     A Item Delegate for custom formatting of predictions/probabilities
     """
@@ -750,11 +754,6 @@ def helpEvent(self, event, view, option, index):
 
     def initStyleOption(self, option, index):
         super().initStyleOption(option, index)
-        if self.parent().selectionModel().isSelected(index):
-            option.state |= QStyle.State_Selected \
-                            | QStyle.State_HasFocus \
-                            | QStyle.State_Active
-
         if self.class_values is None:
             option.displayAlignment = \
                 (option.displayAlignment & Qt.AlignVertical_Mask) | \


Test patch: