获取当前索引号 QStackedWidget

Get current index number QStackedWidget

我编写了一个 PyQt 应用程序,我在其中使用了 QStackedWidget。我想获取当前小部件 index/number。我怎样才能取回它?

currentIndex : int
This property holds the index position of the widget that is visible
The current index is -1 if there is no current widget.
By default, this property contains a value of -1 because the stack is initially empty.

https://doc.qt.io/qt-5/qstackedwidget.html#currentIndex-prop


QWidget *QStackedWidget::currentWidget() const
Returns the current widget, or nullptr if there are no child widgets.

https://doc.qt.io/qt-5/qstackedwidget.html#currentWidget