[PyQt] negative index "setWidget" not working as expected
Sebastian Elsner
sebastianelsner at freenet.de
Thu Jul 28 10:59:53 BST 2011
Hallo,
inserting widgets with a negative index does not work as expected. I was
expecting -1 to add a widget to the end and -2 to insert it right before
the last widget in the layout. Is my assumption wrong?
Demo code:
from PyQt4.QtGui import QLineEdit, QCheckBox, QPushButton, QDialog,
QFormLayout, \
QVBoxLayout, QApplication
class Gui(QDialog):
def __init__(self):
QDialog.__init__(self)
editLayout = QFormLayout()
editLayout.addRow("enter something:", QLineEdit())
editLayout.addRow("enter another something:", QLineEdit())
button = QPushButton("press me")
layout = QVBoxLayout()
layout.addLayout(editLayout)
layout.addWidget(button)
self.setLayout(layout)
self.layout().insertWidget(-2, QCheckBox("check me!"))
app = QApplication([])
g = Gui()
g.show()
app.exec_()
cheers
Sebastian
More information about the PyQt
mailing list