mercredi 17 juillet 2019

A string of consecutive check boxes in pyqt

I would like to create a number of consecutive checkboxes [X] with labels in pyqt5. Most of the similar questions I have found an online deal with aligning the checkboxes in a grid. I don't want that. I just want them side by side with a little descriptive text in between.

I suspect this is very easy to do, but this is my first attempt to make a simple GUI so I don't really know what I'm doing. Ideally, I'm trying to get something that looks like this:

Heading_text [X] text1, [X] text2, [X] text3, [X] text4 [OK]

from PyQt5 import QtWidgets

class Test(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
       self.checkBoxA   = QtWidgets.QCheckBox("text1")
       self.checkBoxB   = QtWidgets.QCheckBox("text2")
       self.checkBoxC   = QtWidgets.QCheckBox("text3")
       self.checkBoxD   = QtWidgets.QCheckBox("text4")
       self.checkboxes = [self.checkBoxA, self.checkBoxB, self.checkBoxC, self.checkBoxD]

       for checkbox in self.checkboxes:
            # print checkboxes in a list....




Aucun commentaire:

Enregistrer un commentaire