[solved] Aspect ratio and text resize



  • Hi,

    It's quite an easy question so I start right away:

    1. Are there any options to set the aspect ratio of a button to a fixed value? I would like to have three QPushButtons in a horizontal layout and let them keep a 1:1 ratio. I only read that you have to inherit from QPushButton and then rewrite events.

    2. Is it possible to let the label inside a button resize with the button? so if the button gets resized to twice the height, the font should be twice as big as well.

    That's it. I didn't found an easy solution to these (in my opinion) easy tasks. Maybe you can help me. :)

    Best regards!


  • Lifetime Qt Champion

    Hi,

    1. No there are not

    2. Yes there is but not without work

    The task might seem easy but you are going outside QPushButton's use case. So you will probably have to start with a QAbstractButton and handle the resizing, font size etc. yourself



  • Hi,

    I figured it out. ;)
    1): I made a sublass from QPushButton which implements the resizeEvent like this:

    @void IconButton::resizeEvent (QResizeEvent * event ) {
    this->setFixedWidth(event->size().height());
    }@

    It's quite simpel and surely doesn't work in every scenario but it works for my case. :)

    1. The same as 1) but this time I worte some lines which resize the font.

    Is there a reason to use QAbstractButton instead?

    Regards


  • Lifetime Qt Champion

    It depends on your customization going from scratch may be simpler, but it seems you don't need to go that far :)

    Since you have it working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.