2

I tried to connect Qt signal of QgsCheckableComboBox when checkedItemsChanged.

I tried below:

def showEvent(self, event):
    print("show event")
    self.loadLayersToCombox()
    self.cmbLayers.checkedItemsChanged.connect(self.updateLables)

def loadLayersToCombox(self):
    layers = [x.name() for x in QgsProject().instance().mapLayers().values()]
    self.cmbLayers.clear()
    self.cmbLayers.addItems(layers)

def updateLables(self):
    print("updateLables")
    chkditems = self.cmbLayers.checkedItems()
    self.checkedlayer = [self.getLayer(x) for x in chkditems if self.getLayer(x) is not None]
    for x in self.checkedlayer:
        self.totalvalue = + x.featureCount()
    print(self.totalvalue)
    self.lblCurrentval.setText("0")
    self.lblTotalval.setText(str(self.totalvalue))

def getLayer(self, name):
    try:
        return self.project.mapLayersByName(name)[0]
    except IndexError:
        return None

I am using QGIS 3.14 below

self.cmbLayers.checkedItemsChanged.connect(self.updateLables)

not connecting self.updateLables.

2
  • 1
    It is a bit unclear for me what you means with the lines after your code: "I am using QGIS 3.14 below (...)" But when looking through the batch of code, my question would be: Is ShowEvent() ever called? That is where the connection is set up in that part of code. Jan 3 at 12:46
  • @Velugoti is right. It doesn't work as expected.
    – user156679
    Jan 3 at 16:17
0

You would need to use a more recent version of QGIS to use the checkedItemsChanged signal. The signal not being emitted was indeed a bug which got fixed rather recently (in this Pull Request). A backport to QGIS LTR 3.16 also seemed to never have happened. I assume you will need at least version 3.20, which was the first release after that PR has been merged.

0

Use currentTextChanged insted checkedItemsChanged

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.