I have created a tab widget window with four tabs in Qt Designer. In python, I then assigned these four tabs to QTabWidget (not sure why I have to do this). These four tabs are recognized. I ensure that signals are not blocked. When I run this code, no signal is recognized upon a change of tabs. Function onChange does not run. This is my code. Can anyone help?
import sys
import subprocess
from PyQt6.QtWidgets import QMainWindow, QApplication, QMessageBox
from PyQt6 import QtCore, QtGui
from PyQt6.QtCore import QObject, QCoreApplication, pyqtSignal
from PyQt6.uic import loadUi
from PyQt6.QtWidgets import QDialog, QTabWidget, QWidget
from datetime import datetime, date
class MainUI(QMainWindow):
def __init__(self):
super(MainUI, self).__init__()
print('check 1')
loadUi('D:/virtual1/AI-Project/AI_Main.ui', self)
print('check 2')
self.tabs = QTabWidget()
# add the qt designer tabs to QTabWidget
self.tabs.addTab(QWidget(), "tab_0")
self.tabs.addTab(QWidget(), "tab_1")
self.tabs.addTab(QWidget(), "tab_2")
self.tabs.addTab(QWidget(), "tab_3")
print('check 3')
# check how many tabs are recognized
no_tabs = self.tabs.count()
print('tab count =', no_tabs)
# ensure signal is not blocked
answer = self.tabs.blockSignals(False)
print('answer blocked = ', answer)
self.tabs.currentChanged.connect(self.onChange)
print('current index =', self.tabs.currentIndex())
def onChange(self):
num = self.tabs.currentIndex()
print('num = ', num)
if num == 0:
print('Index 0')
if num == 1:
print('Index 1')
if num == 2:
print('Index 2')
f num == 3:
print('Index 3')
# self.get_options()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainUI()
indow.show()
app.exec()
I have tried many attempts to debug this code with the assistance of BARD (AI). I have embedded many debugging prints. When I test, I get no signals (onChange does not activate) whenever I click to change the tabs. Bard says the code is good. Confused.