code: def mousePressEvent(self, event):
          
          self._moveItemStarted = False
          rect = QtCore.QRect(0, 0, 12, self.height())
  
          # drag the tab off
          if not self._locked and rect.contains(event.pos()):
              tabbar = self.parent()
              panel = tabbar.parent()
  
              index = tabbar.indexOf(self)
              view = panel.widget(index)
              pixmap = QtGui.QPixmap.grabWidget(view)
  
              drag = QtGui.QDrag(panel)
              data = QtCore.QMimeData()
              data.setData('x-application/xview/tabbed_view', QtCore.QByteArray(str(index)))
              drag.setMimeData(data)
              drag.setPixmap(pixmap)
  
              if not drag.exec_():
                  cursor = QtGui.QCursor.pos()
                  geom = self.window().geometry()
                  if not geom.contains(cursor):
                      view.popout()
  
          # allow moving indexes around
          elif not self._locked and self.isActive():
              self._moveItemStarted = self.parent().count() > 1
  
          else:
              self.activate()
  
          super(XViewPanelItem, self).mousePressEvent(event)
docs: Creates the mouse event for dragging or activating this tab.
  
          :param      event | <QtCore.QMousePressEvent>