I am using pyside6 in the current version 6.5.1. I encounter the following problem which I did not have in version 6.4.2. The buttons displayed in the main window are assigned object names, which are to be printed by clicking. However, all buttons always print "row=0, col=0" after click. The same happens with other widget attributes.
from PySide6.QtWidgets import QPushButton, QWidget, QMainWindow, QGridLayout, QApplication
class CustomButton(QPushButton):
def __init__(self, parent: QWidget, row: int, col: int, slot: Callable):
super().__init__(parent=parent)
self.setObjectName(f'{row=}, {col=}')
self.setText(f'{row=}, {col=}')
self.released.connect(lambda: slot(self))
class MainWindow(QMainWindow):
def __init__(self, parent: QApplication):
super().__init__()
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.layout = QGridLayout(self.central_widget)
self.create_buttons()
def create_buttons(self):
for r in range(10):
for c in range(10):
button = CustomButton(self, r, c, self.button_clicked)
self.layout.addWidget(button, r, c)
def button_clicked(self, button: QPushButton):
print(button.objectName())
if __name__ == '__main__':
app = QApplication()
window = MainWindow(app)
window.show()
app.exec()
With version 6.4.2, however, the correct object names are printed. What could be the reason for this?