Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Aspect ratio and text resize
Forum Updated to NodeBB v4.3 + New Features

[solved] Aspect ratio and text resize

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RuhigBrauner
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RuhigBrauner
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved