I have a predefined widget with qtDesigner, and I want to use it in several tabs. If I add several times a new tab by adding the widget, it only does it once. For example:
for i in range(3):
self.tab_widget_name.addTab(self.widget_name, str(i))
Such as @user3419537 mentioned, you have to create new widget for each tab, it's not enough to change label of the tab.
self.tabs = QTabWidget(self)
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
self.tabs.addTab(self.tab1, "1")
self.tabs.addTab(self.tab2, "2")
self.tabs.addTab(self.tab3, "3")
Alternatively, you can do it in a for loop, but you might loose reference to the tab widget (if you don't mind):
for i in range(3):
self.widget_name = QWidget()
self.tab_widget_name.addTab(self.widget_name, str(i))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.