在python中,在从一个标签页移动到另一个标签页时使用PyQt5,需要使用索引号将小部件从源页面移动到目标标签页。
我正在尝试以下代码。但不知道。任何人都可以指导我。谢谢
从PyQt5导入QtCore,QtGui,QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1251, 645)
self.tabWidget = QtWidgets.QTabWidget(Form)
self.tabWidget.setGeometry(QtCore.QRect(40, 40, 1161, 571))
self.tabWidget.setObjectName("tabWidget")
self.tab_1 = QtWidgets.QWidget()
self.tab_1.setObjectName("tab_1")
self.tabWidget.addTab(self.tab_1, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.tabWidget.addTab(self.tab_2, "")
self.tabWidget.currentChanged.connect(self.header_Tab_Changed)
global TAB_OPTION
if TAB_OPTION==0:
self.pushButton = QtWidgets.QPushButton(self.tab_1)
self.pushButton.setGeometry(QtCore.QRect(290, 130, 631, 161))
self.pushButton.setObjectName("pushButton")
elif TAB_OPTION==1:
self.pushButton = QtWidgets.QPushButton(self.tab_2)
self.pushButton.setGeometry(QtCore.QRect(100, 100, 431, 61))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Form)
def header_Tab_Changed(self,index):
global TAB_OPTION
TAB_OPTION=index
#I need to move the push button between tabs ????????????????
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_1), _translate("Form", "First-Page"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Form", "Second-Page"))
self.pushButton.setText(_translate("Form", "PushButton"))
if __name__ == "__main__":
import sys
global TAB_OPTION
TAB_OPTION=0
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Form()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())