I'm facing a problem that I cannot solve, even if it shouldn't be difficult.
I have a QListWidget
with 5 items (so 5 rows) and 2 related QStackedWidgets
. The first made of 3 pages: the first page of it contains another nested QStackedWidgets
with 2 pages. So a total pf 5 pages.
A small gif to have an idea:
Now what I'm trying to do is to create a function that links the QListWidget
and the 2 QStackedWidget
. I would like that the item 1 and 2 of the QListWidget
were linked only to the first page of the parent QStackedWidget
and the first and second page of the nested QStackedWidget
while item 3, 4 and 5 were linked only to the parent QStackedWidget
(2nd, 3rd and 4th page).
The piece of code I wrote is the following:
# connect the listWidget currentRow signal to a custom function
self.listWidget.currentRowChanged.connect(self.updateStacked)
def updateStacked(self):
idx = self.listWidget.currentRow()
if idx is 0 or idx is 1:
self.stackedPlotWidget.setCurrentIndex(0)
self.stackedNestedWidget.setCurrentIndex(1)
else:
self.stackedPlotWidget.setCurrentIndex(idx - 1)
but something is not working correctly: for QlistWidget
rows 0 and 1 works nice but it seems not taking into account the else statement.
Some suggestions?