Skip to content

Commit

Permalink
OWWidget: Preserve widget geometry between hide/show events
Browse files Browse the repository at this point in the history
The fix from gh-2027 did not execute when the widget had no existing
saved geometry to restore (i.e. on first use or after 'Reset Widget
Settings' was run).
  • Loading branch information
ales-erjavec committed Oct 12, 2018
1 parent 8f507ed commit e529f57
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Orange/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class OWWidget(QDialog, OWComponent, Report, ProgressBarMixin,
contextOpened = Signal()
contextClosed = Signal()

# pylint: disable=protected-access
# pylint: disable=protected-access, access-member-before-definition
def __new__(cls, *args, captionTitle=None, **kwargs):
self = super().__new__(cls, None, cls.get_flags())
QDialog.__init__(self, None, self.get_flags())
Expand Down Expand Up @@ -207,6 +207,8 @@ def __new__(cls, *args, captionTitle=None, **kwargs):

# flag indicating if the widget's position was already restored
self.__was_restored = False
# flag indicating the widget is still expecting the first show event.
self.__was_shown = False

self.__statusMessage = ""

Expand Down Expand Up @@ -573,16 +575,6 @@ def _fullscreen_to_maximized(geometry):
y = max(0, space.height() / 2 - height / 2)

self.move(x, y)

# Mark as explicitly moved/resized if not already. QDialog would
# otherwise adjust position/size on subsequent hide/show
# (move/resize events coming from the window manager do not set
# these flags).
if not self.testAttribute(Qt.WA_Moved):
self.setAttribute(Qt.WA_Moved)
if not self.testAttribute(Qt.WA_Resized):
self.setAttribute(Qt.WA_Resized)

return restored

def __updateSavedGeometry(self):
Expand Down Expand Up @@ -654,6 +646,15 @@ def showEvent(self, event):
if self.savedWidgetGeometry is not None:
self.__restoreWidgetGeometry(bytes(self.savedWidgetGeometry))
self.__was_restored = True

if not self.__was_shown:
# Mark as explicitly moved/resized if not already. QDialog would
# otherwise adjust position/size on subsequent hide/show
# (move/resize events coming from the window manager do not set
# these flags).
self.setAttribute(Qt.WA_Moved, True)
self.setAttribute(Qt.WA_Resized, True)
self.__was_shown = True
self.__quicktipOnce()

def wheelEvent(self, event):
Expand Down

0 comments on commit e529f57

Please sign in to comment.