我有一个QStackedWidget的子类,里面有一个QWidget的子类。在QWidget中,我想单击一个按钮,该按钮将转到QStackedWidget的下一页。我的(简化)方法如下:
class Stacked(QtGui.QStackedWidget):
def __init__(self, parent=None):
QtGui.QStackedWidget.__init__(self, parent)
self.widget1 = EventsPage()
self.widget1.nextPage.connect(self.nextPage)
self.widget2 = MyWidget()
self.addWidget(self.widget1)
self.addWidget(self.widget2)
def nextPage(self):
self.setCurrentIndex(self.currentIndex() + 1)
class EventsPage(QtGui.QWidget):
nextPage = QtCore.pyqtSignal()
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.continueButton = QtGui.QPushButton('Continue')
self.continueButton.clicked.connect(self.nextPage)
所以,基本上,我将continueButton clicked
信号连接到EventsPage nextPage
信号,然后将其堆栈连接到nextPage
方法。我可以在Stacked and connectself.widget1.continueButton.clicked
中深入研究EventsPage的内部,但这似乎完全违背了信号和插槽的用途。在
那么,这种方法有意义吗,还是有更好的方法呢?在
不,这很有道理。把信号想象成人们从楼顶招手。他们不想穿过街道(所有的楼梯…),所以他们会观察其他建筑物上的其他人在做什么。这样,就没人关心大楼里发生了什么。在
相关问题 更多 >
编程相关推荐