Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QCommandLinkButton stops working when I recreate it



  • Hi guys, basically when I recreate the QCommandLinkButton it stop working (stop printing), someone can identify where is the problem?

    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
    
            # ....
            # GUI CODE BETWEEN 
            # ....
    
    
            # create the button
            self.del_and_create()
    
    
            # another button to call del_and_create()
            self.btn_new_user2.clicked.connect(self.del_and_create)
    
    
            # if button HOST_1 pressed print "working"
            self.host_1.clicked.connect(lambda: print('working'))
    
        # del and creathe the HOST_1
        def del_and_create(self):
            try:
                self.host_1.deleteLater()
                print('removing the button')
            except:
                pass
    
            # create button
            self.host_1 = QCommandLinkButton(self.scrollAreaWidgetContents_2)
            self.host_1.setObjectName(u"commandLinkButton_1")
            self.host_1.setMinimumSize(QSize(26, 36))
            self.host_1.setMaximumSize(QSize(135, 36))
            self.host_1.setCursor(QCursor(Qt.PointingHandCursor))
            self.host_1.setIconSize(QSize(17, 17))
            self.gridLayout_4.addWidget(self.host_1, 0, 0, 1, 1)
            self.host_1.setText(QCoreApplication.translate("MainWindow", 'hosts', None))
    

    STDOUT:
    405cfb84-4b1f-497c-9438-c3cc22cdc2c5-image.png


  • Lifetime Qt Champion

    @Black-Cat You gorgot to connect the clicked signal from the new button...