dndwidgets: improvements

This commit is contained in:
Simon Renblad 2024-01-15 17:22:45 +08:00
parent 19bcc2357b
commit 780e0bada8

View File

@ -23,6 +23,7 @@ class DragDropSplitter(QtWidgets.QSplitter):
pos = e.pos() pos = e.pos()
src = e.source() src = e.source()
src_i = self.indexOf(src) src_i = self.indexOf(src)
self.setRubberBand(self.height())
# case 0: smaller than source widget # case 0: smaller than source widget
if pos.y() < src.y(): if pos.y() < src.y():
for n in range(src_i): for n in range(src_i):
@ -34,8 +35,8 @@ class DragDropSplitter(QtWidgets.QSplitter):
elif pos.y() > src.y() + src.size().height(): elif pos.y() > src.y() + src.size().height():
for n in range(src_i + 1, self.count()): for n in range(src_i + 1, self.count()):
w = self.widget(n) w = self.widget(n)
if pos.y() < w.y() + w.size().height(): if pos.y() < w.y():
self.setRubberBand(w.y() + w.size().height()) self.setRubberBand(w.y())
break break
else: else:
self.setRubberBand(-1) self.setRubberBand(-1)
@ -46,16 +47,7 @@ class DragDropSplitter(QtWidgets.QSplitter):
pos = e.pos() pos = e.pos()
src = e.source() src = e.source()
src_i = self.indexOf(src) src_i = self.indexOf(src)
# case 0: smaller than source widget for n in range(self.count()):
if pos.y() < src.y():
for n in range(src_i):
w = self.widget(n)
if pos.y() < w.y() + w.size().height():
self.insertWidget(n, src)
break
# case 2: greater than source widget
elif pos.y() > src.y() + src.size().height():
for n in range(src_i + 1, self.count()):
w = self.widget(n) w = self.widget(n)
if pos.y() < w.y() + w.size().height(): if pos.y() < w.y() + w.size().height():
self.insertWidget(n, src) self.insertWidget(n, src)