0

I have a class named walletWidget that inherits QWidget. When I add it to a Layout (QGridLayout, QVBoxLayout...) setStyleSheet isn't working.

This is class that inherits QWidget.

class walletWidget(QWidget):
    def __init__(self, name, currency):
        super().__init__()

        self.LFONT = QFont("Arial", 25, QFont.Bold)
        self.MFONT = QFont("Arial", 15, QFont.Bold)
        self.SFONT = QFont("Arial", 10, QFont.Bold)

        self.name = name
        self.currency = str(currency)

        self.gui()

    def gui(self):
        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.title = QLabel(self.name)
        self.title.setFont(self.LFONT)
        self.title.setAlignment(Qt.AlignTop)

        self.currencyLabel = QLabel("Money : ")
        self.currencyLabel.setFont(self.MFONT)

        self.currency = QLabel(self.currency)
        self.currency.setFont(self.MFONT)

        self.editButton = QPushButton("Edit")
        self.editButton.setFont(self.SFONT)
        self.editButton.clicked.connect(self.editTitle)

        self.delButton = QPushButton("Delete")
        self.delButton.setFont(self.SFONT)
        self.delButton.clicked.connect(self.delWallet)

        self.continueButton = QPushButton("Continue")
        self.continueButton.setFont(self.MFONT)

        self.layout.addWidget(self.title, 0, 0, 1, 2,
                              alignment=Qt.AlignHCenter)
        self.layout.addWidget(self.currencyLabel, 1, 0,
                              1, 1, alignment=Qt.AlignTop)
        self.layout.addWidget(self.currency, 1, 1, 1, 1, alignment=Qt.AlignTop)
        self.layout.addWidget(self.continueButton, 2, 0, 1, 2)
        self.layout.addWidget(self.editButton, 3, 0, 1, 1)
        self.layout.addWidget(self.delButton, 3, 1, 1, 1)

        self.layout.setRowStretch(0, 1)
        self.layout.setRowStretch(1, 2)
    def addWallets(self):
        for i in wallets:
            self.startWidget.label = walletWidget(i["name"], 10000)
            self.startWidget.label.setObjectName("walletWidget")
            self.startWidget.label.setMaximumWidth(300)
            self.startWidget.walletAreaLayout.addWidget(self.startWidget.label, 0, i["index"])

        if len(wallets) != 3:
            self.startWidget.newWallet = QPushButton()
            self.startWidget.newWallet.setMaximumSize(120, 120)
            self.startWidget.newWallet.setIcon(QIcon(iconPath + "square-plus.svg"))
            self.startWidget.newWallet.setIconSize(QSize(100, 100))
            self.startWidget.newWallet.setObjectName("addWalletButton")
            self.startWidget.newWallet.clicked.connect(addWallet)
            self.startWidget.walletAreaLayout.addWidget(self.startWidget.newWallet, 0, len(wallets))

I have a main widget called startWidget. I am trying to add walletWidget to a QGridLayout inside startWidget. But it doesn't work.

This is what happens :here This is what I want (borders, just example) : here

I tried to use setStyleSheet inside walletWidget but it also didn't work. It just applied it items in it not whole widget. like this

  • If you don't tell us how you set the stylesheet, to what, and with what contents, we cannot help you, please provide a valid [mre]. Also be aware that custom QWidget subclasses don't use stylesheets by defuault, unless you use the style to draw its primitive or use `setAttribute(Qt.WA_StyledBackground)`. See [this answer](https://stackoverflow.com/q/7276330). – musicamante May 06 '23 at 22:04

0 Answers0