I am currently attempting to set boundaries so that tabs cannot move beyond on each end of my QTabBar. By default the movable tab just disappears into void whenever it is dragged outside of the QTabBar's area - An example of the QTab being dragged outside of the QTabBar's Area.
This is fine for the most part, but visually I would like the tab to stop moving entirely once it reaches the edge of the QTabBar. I've attempted to accomplish this goal via Qt's event system, and currently only have support for the left boundary. Whenever the user clicks on a QTab, I record his mouse's initial position and the current tabs unmoved position and size. I then use these values to determine at which x-position the current tab would reach the edges of the QTabBar if the user were to move his mouse left. If this position is ever reached the event is filtered preventing any further movement of the tab.
def eventFilter(self, source, event):
if event.type() == QEvent.Type.MouseButtonPress:
self.startingpos = event.x()
self.tabOrigin = self.curTab.x()
self.tabRoom = self.startingpos - self.tabOrigin
if event.type() == QEvent.Type.MouseMove:
if self.curIndex != self.tabs.currentIndex():
self.curIndex = self.tabs.currentIndex()
self.curTab = self.tabs.tabBar().tabRect(self.curIndex)
if event.x() < self.tabRoom:
return True
return False
This tactic is effective unless the user quickly moves his mouse left. This causes the moving tab to get stuck at the last recorded position of the mouse before it went past the specified boundary, before reaching the QTabBar's edge - An example of the QTab getting stuck before reaching the left side of the QTabBar.
I'm not exactly sure how to get around this issue. I understand that the moving tab is not actually the same one as the tab that is originally clicked. Is there anyway to access the position of the moving tab and manually set its position? If not, any advice about how else to go about solving this problem would be greatly appreciated.