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