1

I am creating a plugin for QGIS but am having trouble with the Qt components. I have used Plugin Builder and Qt designer to create all necessary files for the plugin. I want to use a QStackedWidget inside my QDialog and I can open the dialog just fine when I don't try to access the "pages" (or widgets) of the stacked widget. But I am getting an error when trying to reach the pages/objects located inside the pages of a stacked widget from my code.

Simple code example:

def __init__(self, iface):

    self.dlg = Dialog() 
    self.stackedWidget = self.dlg.stackedWidget
    self.dlg.stackedWidget.page.pushButton.clicked.connect(self.func)

def func(self):
    :code that does some stuff:

Returns the error:

AttributeError: 'QStackedWidget' object has no attribute 'page'

Similarly if I try to work with just a stacked widget not inside a QDialog (again opens just fine without the code that causes errors) I get the same kind of error.

Code Example:

def __init__(self, iface):

    self.stackedWidget = StackedWidget() 
    self.page = self.stackedWidget.page
    self.page.pushButton.clicked.connect(self.func)

def func(self):
    :code that does some stuff:

Returns the error:

AttributeError: 'QWidget' object has no attribute 'pushButton'

What am I doing wrong or what is causing the error?

0

1 Answer 1

2

There is no page attribute on the QStackWidget object. Here are all the methods that it has: http://doc.qt.io/qt-4.8/qstackedwidget.html

What you need to do get the widget is call the widget function:

widget = self.stackedWidget.widget(index)

where index is the page index of the widget.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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