Unsolved itemClicked Signal from QListWidget gets not called
-
Hey everybody,
this is my first post here so please be gentle ;) I'm a newbie in python QT development. I'm trying to build an application with a gui created in QT Designer. In my main.py script i'm loading and executing the GUI. All this is working fine. In my app there are different QListWidgets. I use self.[variablenames].itemClicked.connect([Function]) inside the init to fetch the signals.
The wierd thing is: for the one listwidget it's working fine. Once I copy the the code and modify it for another listwidget it gets fucked up.
Hope you can help! Here's a piece of code. I set a print inside the
Thanks a lot!!class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) #run DB self.iDB = sqlite3.connect("local.db") self.iCursor = self.iDB.cursor() self.impactFunc = impact(self.iDB) self.pF = projections(self.iDB) self.impactUiFunc = impactUi() self.cF = consistency(self.iDB) # --- Taskleiste self.ui.actionExcelImport.triggered.connect(self.excelImport) self.ui.actionExcelExport.triggered.connect(self.excelExport) # --- General #set status lights in tab self.ui.tab.setTabIcon(0,QIcon('images/construction.png')) self.ui.tab.setTabIcon(1,QIcon('no.png')) self.ui.tab.setTabIcon(2,QIcon('no.png')) self.ui.tab.setTabIcon(3,QIcon('no.png')) # --- Impact self.ui.impact_remove_btn.clicked.connect(self.deleteImpactFactor) self.ui.impact_run_btn.clicked.connect(self.keyFactSelec) self.ui.impact_add_btn.clicked.connect(self.addImpactFactor) # --- Projections self.ui.proj_keyFactList.itemClicked.connect(self.showProjection) ### !!! This is working fine! self.ui.proj_edit_btn.clicked.connect(self.projEdit) # --- Consistency self.ui.cons_ProjB_list.itemClicked.connect(self.loadConsistency(0,1,2)) ### !!! This gets fucked up!
the function to execute is:
def loadConsistency(self,keyFactorID_A, keyFactorID_B, change): print("hi") #Projektionen laden if change <=1: #wenn nur FaktorA oder beide geaendert self.ui.cons_projA2.clear() self.ui.cons_projA3.clear() a = self.pF.getProjections(keyFactorID_A) a = a[1] if len(a) >= 1: self.ui.cons_projA1.setText(a[0]) if len(a) >= 2: self.ui.cons_projA2.setText(a[1]) if len(a) >= 3: self.ui.cons_projA3.setText(a[2]) if change == 2 or change == 0: #wenn nur FaktorB oder beide geaendert self.ui.cons_projB2.clear() self.ui.cons_projB3.clear() a = self.pF.getProjections(keyFactorID_B) a = a[1] if len(a) >= 1: self.ui.cons_projB1.setText(a[0]) if len(a) >= 2: self.ui.cons_projB2.setText(a[1]) if len(a) >= 3: self.ui.cons_projB3.setText(a[2])
-
@mscUPB said in itemClicked Signal from QListWidget gets not called:
self.ui.cons_ProjB_list.itemClicked.connect(self.loadConsistency(0,1,2))
How is this supposed to work?
You are calling the slot here self.loadConsistency.
It must be:self.ui.cons_ProjB_list.itemClicked.connect(self.loadConsistency)
If you want to pass parameter use a lambda as slot.
-
Thanks for the fast response! I tried it out but the function still doesn't get executed :(
-
@mscUPB Show what you tried. And did you check whether there are any runtime errors/warnings?
-
@mscUPB
Well, it should do, provided theself.ui.cons_ProjB_list.itemClicked
signal really is getting emitted.... Attach the signal to e.g. yourself.showProjection
. which you know works, just to prove. -
I tried with the function which is connected to the working piece:
self.ui.cons_ProjB_list.itemClicked.connect(self.showProjection)
Nothing happens, even no warnings or errors. I guess the signal is not getting emitted
if i try self.ui.cons_ProjB_list.itemClicked.connect(print("Hi")) nothing is happening on item click but the Hi get's printed once running the Main script. -
@mscUPB said in itemClicked Signal from QListWidget gets not called:
if i try self.ui.cons_ProjB_list.itemClicked.connect(print("Hi")) nothing is happening on item click but the Hi get's printed once running the Main script.
Of course "Hi" will be printed once as you are CALLING print() here:
self.ui.cons_ProjB_list.itemClicked.connect(print("Hi"))
If you connect a signal to a slot you do NOT call the slot, this is something you have to learn! The slot gets called when signal is emitted.