View Single Post
Old 07-30-2014, 07:55 AM   #1
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
Simple PyQt help, please

I'm trying to tidy up the widget creating/layout code in a rather large QDialog which contains many QGroupBox widgets each of which contains a list of buttons. For each groupbox the buttons will all be QPushButton or all QCheckBox.
  1. I've managed to code a working method which successfully creates the groupbox/buttonlist pairs but I need a bit of help. The code currently is something like this:
    Code:
    def create_groupbox(self, lvalues, widget='QPushButton'):
        ... ...
        buttonlist = []
        for val in lvalues:
            ... ...
            if widget == 'QPushButton':
                button = QPushButton()
            elif widget == 'QCheckBox':
               button = QCheckBox()
            button.setText(val)
            ... ...
            buttonlist.append(button)
        ... ...
        return buttonlist, groupbox
    Is there better 1-line code for the red bit?
  2. A follow-up question. If I've previously created a groupbox/buttonlist pair using the above method,
    e.g. self.blist, gbox = self.create_groupbox(['1em', '2em', '3em'])
    and elsewhere in the code I need to know whether self.blist was created using QPushButton or QCheckBox, is there a test I could use on self.blist[0] to answer that question?
jackie_w is offline   Reply With Quote