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

deleting and redraw new buttons



  • hello,
    i'm new on QT, and i work (for blender), to have a character picker.
    for each part of my character, i create a button to select it.
    so because i have potentially several character, with some special parts (like dress or short) i create a button to delete and re-create buttons for selecting parts. deleting is ok, recreate seem working well, but no (new) buttons are visibles. and i don't understand why. i try several things, but nothing...

    my init part:

        def init_ui(self):
            # layout general
            self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
            ###------------------------------------------------------###
            #self.verticalLayout = QtWidgets.QVBoxLayout(self)
            #self.verticalLayout.setObjectName('verticalLayout')
    
            self.topLeftLayout = QtWidgets.QWidget(self)
            self.topLeftLayout.setGeometry(QtCore.QRect(0, 0, 300, 200))
            self.topLeftLayout.setObjectName("topLeftLayout")
    
            self.topMiddleLayout = QtWidgets.QWidget(self)
            self.topMiddleLayout.setGeometry(QtCore.QRect(300, 0, 300, 200))
            self.topMiddleLayout.setObjectName("topMiddleLayout")
    
            self.topRightLayout = QtWidgets.QWidget(self)
            self.topRightLayout.setGeometry(QtCore.QRect(600, 0, 300, 200))
            self.topRightLayout.setObjectName("topRightLayout")
    
            self.pantinLayout = QtWidgets.QWidget(self)
            self.pantinLayout.updatesEnabled()
            self.pantinLayout.setGeometry(QtCore.QRect(250, 200, 500, 600))
            self.pantinLayout.setObjectName("topRightLayout")
    
            ###-------------------------------------------------------###
            self.Radio_obj_name = QtWidgets.QPushButton("update character", parent=self.topLeftLayout)
            self.Radio_obj_name.setObjectName(u"pushButton")
            self.Radio_obj_name.setGeometry(QtCore.QRect(10, 10, 120, 23))
            self.Radio_obj_name.setCheckable(True)
    
            ###-------------------------------------------------------###
    
            self.butgroup = QtWidgets.QButtonGroup(self)
            self.createPantin()
            self.Radio_obj_name.clicked.connect(self.change_character)
    

    the creation part for character buttons

        def createPantin(self):
            if len(bpy.context.view_layer.objects.selected) > 0:
                sel = bpy.context.view_layer.objects.selected[0]
                if sel.type == 'ARMATURE':
                    print("parla")
                    self.pantpart = []
    
                    # creation des switch
                    for i in self.swt:
                        if i in self.layers:
                            self.createSwitch(i)
                    # creation du pantin
                    for i in self.bmps:
                        for j in self.buttons:
                            for k in self.buttons[j]:
                                if i == k:
                                    name = self.bmpPath+i+".png"
                                    self.path = name.replace("\\","/")
                                    self.but = QtWidgets.QPushButton("", parent=self.pantinLayout)
                                    self.but.setAccessibleName(j+"/"+i)
                                    self.but.setGeometry(
                                                        (self.bmps[i][0]/self.ratio)-self.Hoffset,
                                                        (self.bmps[i][1]/self.ratio)-self.Voffset,
                                                        self.bmps[i][2]/self.ratio,
                                                        self.bmps[i][3]/self.ratio
                                                        )
                                    self.but.setStyleSheet("QPushButton{image:url("+self.path+"); border:none}")
                                    self.butgroup.addButton(self.but)
                                    self.pantpart.append(self.but)
    
    
                    # connection bouton
                    self.butgroup.buttonClicked.connect(self.selectpart)                
    

    and the code called by the button to update

        def change_character(self):
            #self.verticalLayout.removeWidget(self.pantinLayout)
            #self.pantinLayout.deleteLater()
            for i in self.pantpart:
                i.deleteLater()
    
            self.characterID()
            self.organize()
            self.createPantin()
            for i in self.pantpart:
                i.repaint()
                i.update()
    

    if someone could explain me what i don't understand


  • Lifetime Qt Champion

    @chabis Call show() on each created button.



  • humm... i've try but nothing change.
    ... it's a mystery for me


  • Lifetime Qt Champion

    @chabis Did you debug your code? Did you verify that buttons were indeed created? Did you verify whether you set proper geometry (not sure why you do that at all)?



  • yes , i've done all i can, and finally it's ok.
    and the problems seem to be in the widget where i put my buttons. all was create correctly but nothing was visible. i 've changed the kind of widget i use, and now it's ok.
    (i need to say that not is clear in my mind about how qt is working.)

    thanks for all @jsulm


Log in to reply