That's not a good approach, you are not taking margins and spacing into consideration. It will fail if you click near a border of a tab. Use QWidget::mapTo() like this:
Qt Code:
  1. QPoint tabBarPoint = mapTo(tabBar()), event->pos());
  2. int index = tabBar()->tabAt(tabBarPoint);
To copy to clipboard, switch view to plain text mode