'PyQt5 TabWidget tabBarClicked TypeError: native Qt signal is not callable
I am trying to making a user interface with PyQt5. If i click the 5th index tab userSettings() function will call. But program raises this error:
self.tabWidget.tabBarClicked(5).connect(self.userSettings())
TypeError: native Qt signal is not callable
How can i fix it?
import sys
import PyQt5.QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QTabBar, QWidget
from PyQt5.QtWidgets import QMessageBox
from numpy import *
from alfa_gui import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)
self.tabWidget.tabBarClicked(5).connect(self.userSettings())
def userSettings(self):
if self.lineEdit.text() == "cogal" and self.lineEdit_2.text() == "cogal":
print("Success!")
else:
msg = QMessageBox()
msg.setWindowTitle("Hatalı Giriş!")
msg.setText("Wrong Password Or Username")
x = msg.exec_()
msg.setIcon(QMessageBox.Critical)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.setWindowTitle('ALFA')
window.show()
exit_code = app.exec_()
sys.exit(exit_code)
Solution 1:[1]
Clearly the tabWidget.tabBarClicked is not callable.
I would connect a listener to tabWidget's onchange:
self.tabWidget.currentChanged.connect(self.function_to_run)
Then you can write your function_to_run to check the currentIndex()
...
self.tabs.currentChanged.connect(self.function_to_run)
...
def function_to_run(self):
if self.tabWidget.currentIndex() == 5:
print("Do stuff")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MSH |
