Skip to content

Commit 8bde159

Browse files
committed
StickyGraphicsView: Use inscribed interger rect for visibility test
1 parent b11847c commit 8bde159

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Orange/widgets/utils/stickygraphicsview.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import sys
22
import math
33

4-
from PyQt5.QtCore import Qt, QRectF, QEvent, QCoreApplication, QObject, QPointF
4+
from PyQt5.QtCore import (
5+
Qt, QRectF, QEvent, QCoreApplication, QObject, QPointF, QRect
6+
)
57
from PyQt5.QtGui import QBrush, QPalette, QTransform, QPolygonF
68
from PyQt5.QtWidgets import (
79
QGraphicsView, QGraphicsScene, QWidget, QVBoxLayout, QSizePolicy,
@@ -219,10 +221,10 @@ def __updateView(self, view: QGraphicsView, rect: QRectF) -> None:
219221
return
220222
# map the rect to (main) viewport coordinates
221223
viewrect = qgraphicsview_map_rect_from_scene(self, rect).boundingRect()
222-
viewrect = viewrect.toAlignedRect()
224+
viewrect = qrectf_to_inscribed_rect(viewrect)
223225
viewportrect = self.viewport().rect()
224-
visible = not (viewrect.top() >= viewportrect.top()
225-
and viewrect.bottom() <= viewportrect.y() + viewportrect.height())
226+
visible = (viewrect.top() < viewportrect.top() or
227+
viewrect.y() + viewrect.height() > viewportrect.y() + viewportrect.height())
226228
container.setVisible(visible)
227229
# force immediate layout of the container overlay
228230
QCoreApplication.sendEvent(container, QEvent(QEvent.LayoutRequest))
@@ -263,6 +265,18 @@ def qgraphicsview_map_rect_from_scene(
263265
return QPolygonF([p1, p2, p3, p4])
264266

265267

268+
def qrectf_to_inscribed_rect(rect: QRectF) -> QRect:
269+
"""
270+
Return the largest integer QRect such that it is completely contained in
271+
`rect`.
272+
"""
273+
xmin = int(math.ceil(rect.x()))
274+
xmax = int(math.floor(rect.right()))
275+
ymin = int(math.ceil(rect.top()))
276+
ymax = int(math.floor(rect.bottom()))
277+
return QRect(xmin, ymin, max(xmax - xmin, 0), max(ymax - ymin, 0))
278+
279+
266280
def main(args): # pragma: no cover
267281
# pylint: disable=import-outside-toplevel,protected-access
268282
from PyQt5.QtWidgets import QApplication, QAction

0 commit comments

Comments
 (0)