让我说我知道/从QTabBar中光标下方的标签中获取tabIndex,我怎样才能在我的tabBar中的X选项卡中获取小部件?我不想要CurrentWidget(),因为那很容易,我想得到我想要的每个标签的小部件,以便在我放弃时将正确的一个插入到另一个QTabWidget中。
class ColtTab(qg.QTabWidget):
def __init__(self):
super(ColtTab,self).__init__()
self.setAcceptDrops(True)
self.tabBar = self.tabBar()
self.tabBar.setMouseTracking(True)
#self.tabBar.installEventFilter(self)
self.setDocumentMode(True)
self.indexTab = None
# Events
def mouseMoveEvent(self, e):
if e.buttons() != qc.Qt.MiddleButton:
return
globalPos = self.mapToGlobal(e.pos())
print(globalPos)
tabBar = self.tabBar
print(tabBar)
posInTab = tabBar.mapFromGlobal(globalPos)
print(posInTab)
self.indexTab = tabBar.tabAt(e.pos())
print(self.indexTab)
tabRect = tabBar.tabRect(self.indexTab)
print(tabRect)
print(tabRect.size())
pixmap = qg.QPixmap(tabRect.size())
tabBar.render(pixmap,qc.QPoint(),qg.QRegion(tabRect))
mimeData = qc.QMimeData()
drag = qg.QDrag(tabBar)
drag.setMimeData(mimeData)
drag.setPixmap(pixmap)
cursor = qg.QCursor(qc.Qt.OpenHandCursor)
drag.setHotSpot(e.pos() - posInTab)
drag.setDragCursor(cursor.pixmap(),qc.Qt.MoveAction)
dropAction = drag.exec_(qc.Qt.MoveAction)
def mousePressEvent(self, e):
#super().mousePressEvent(e)
if e.button() == qc.Qt.RightButton:
print('press')
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
e.setDropAction(qc.Qt.MoveAction)
e.accept()
self.insertTab(self.indexTab,self.currentWidget(), self.tabText(self.indexTab))
# HERE IN THE DROP EVENT I NEED TO INSERT THE CORRECT TAB INTO ANOTHER TABWIDGET, BUT I CAN ONLY INSERT THE CURRENT