pyapp-kit / superqt

Missing widgets and components for Qt-python
https://pyapp-kit.github.io/superqt/
BSD 3-Clause "New" or "Revised" License
210 stars 37 forks source link

qcollapsible font size / style #231

Open carsen-stringer opened 9 months ago

carsen-stringer commented 9 months ago

Love the QCollapsible class! (and the rangeslider!) I tried using "setFont" with QCollapsible and couldn't change the font style for the title (like you can for a QGroupBox). Is it possible in a different way? Thanks.

tlambert03 commented 9 months ago

Hey @carsen-stringer,

looks like that hasn't been exposed fully. I'll give you a workaround that uses a private attribute, and we'll have to fix it with a PR. The main text that you see in a QCollapsible (the text that you can click to expand/collapse) is actually a QPushButton that is accessible at QCollapsible._toggle_btn.

So, as a workaround, you could use:

wdg = QCollapsible('toggle me')
font = wdg.font()
# modify the font
wdg._toggle_btn.setFont(font)
tlambert03 commented 9 months ago

it's also perhaps worth nothing that that only adjust the top level text, but not widgets you've added inside. So, another option that doesn't require private attribute access, and which controls all of them:

# where wdg is a QCollapsible
for child in wdg.children():
    if isinstance(child, QWidget):
        child.setFont(font)
carsen-stringer commented 9 months ago

thanks so much! adding it to my code now

On Wed, Feb 14, 2024 at 1:48 PM Talley Lambert @.***> wrote:

it's also perhaps worth nothing that that only adjust the top level text, but not widgets you've added inside. So, another option that doesn't require private attribute access, and which controls all of them:

for child in wdg.children(): if isinstance(child, QWidget): child.setFont(font)

— Reply to this email directly, view it on GitHub https://github.com/pyapp-kit/superqt/issues/231#issuecomment-1944403085, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADS6TFJKSVTHJIO5C5KPB7LYTUBHNAVCNFSM6AAAAABDFXRCXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBUGQYDGMBYGU . You are receiving this because you were mentioned.Message ID: @.***>