[PyQt] QStackedLayout addWidget always returns 0

Lee Harr missive at hotmail.com
Sat Nov 22 16:06:34 GMT 2014


My understanding is that QStackedLayout.addWidget should add the
widget to the end of the stack and return the index of the position at
which it was added.

For some reason, I am always getting 0...

Versions:
Ubuntu 4.10
Python 3.4.2 (default, Oct  8 2014, 13:18:07) [GCC 4.9.1]
PyQt 4.11.2


Example:
import sys
import PyQt4
from PyQt4.QtGui import QWidget, QApplication, QLabel, QStackedLayout

 
class QSLayoutExample(QWidget):
    def __init__(self):
        QWidget.__init__(self)
 
        self.layout = QStackedLayout()
        self.setLayout(self.layout)
  
        for i in range(10):
            w = QLabel(self)
            idx = self.layout.addWidget(w)
            print(idx)
            print(self.layout.count())
 
    def run(self):
        self.show()
        qt_app.exec_()


qt_app = QApplication(sys.argv)
app = QSLayoutExample()
app.run()



Output:
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10



Am I using this wrong? Are my expectations mistaken?


Thanks for any insight.

 		 	   		  


More information about the PyQt mailing list