使用PyQt

时间:2018-06-26 11:01:18

标签: python pyqt pyqt4 qcheckbox qvboxlayout

我想在垂直布局内添加动态复选框。我已经在下面的代码中编写了代码,在第一次加载时显示了动态复选框,但是在特定事件调用中,它没有显示添加的小部件。

class SlotWindow(QMainWindow, Ui_MainWindow):

""" App Main Window that will execute """

def __init__(self, file_path):
    """ set the file path """
    self.file_path = file_path
    super().__init__()
    self.setupUi(self)

    self.reel_check_box = dict()
    self.process.clicked.connect(self.create_slot_xml_file)
    self.reel_strip.currentIndexChanged.connect(self.create_dynamic_reel_options)
    # get the default combox data for basic reel
    reel_name = ReelXmltoDataRead(self.file_path, "Basic").get_name_list()
    self.create_dynamic_combobox(reel_name)


def create_dynamic_combobox(self, reel_names):
    """"""
    print(reel_names)
    for index in self.reel_check_box:
        try:
            self.reel_check_box[index].deleteLater()
        except:
            pass
    self.reel_check_box = dict()
    for index, reel in enumerate(reel_names):
        self.reel_check_box[index] = QCheckBox()
        # self.reel_check_box[index].setGeometry(QtCore.QRect(50, 20 + index*30, 151, 22))
        self.reel_check_box[index].setText(_translate("MainWindow", reel, None))
        self.reel_name.addWidget(self.reel_check_box[index])
    self.show()

def create_dynamic_reel_options(self):
    """ create dynamic reel box """
    print("this method get call")
    reel_name = self.reel_strip.currentText()
    reel_name_list = ReelXmltoDataRead(self.file_path, reel_name).get_name_list()
    self.create_dynamic_combobox(reel_name_list)

create_dynamic_reel_options方法获取某些按钮事件的调用,它将首先删除所有先前的复选框并创建新的复选框,删除旧的复选框,但新的复选框未得到显示。

self.reel_strip是垂直布局

0 个答案:

没有答案