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. QWidget Scaling
Forum Updated to NodeBB v4.3 + New Features

QWidget Scaling

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 4.9k Views 2 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.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by webzoid
    #1

    How would one go about introducing scaling to widgets such as a QPushButton when running on low/high resolution displays?

    For example, an application we have has a side menu widget running vertically down the left side of the screen. Buttons in this widget are layed out vertically and are specified as 64x64px in size. On a high-res display, this looks great but customers running on low-res (1024x768) displays are losing buttons off the bottom of the screen.

    Would would be really nice is to to be able to scale between the minimumSize and maximumSize depending on the overall size of the Application window: at low-res 1024x768, the buttons may reduce to 32x32px whereas from 1920x1080 the buttons increase to 64x64px.

    This would be massively helpful on tablets/phones where the resolutions also vary wildly.

    Please tell me a solution already exists, I just don't know about it! Thanks :)

    Also, the widget would need to maintain a certain aspect ratio. So if the min is 32x32 and max is 64x64, the widget would never achieve a size of say 42x48 but 48x48 would be valid.

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

      Hi,

      Usually, with widgets you use layouts.

      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
      2
      • webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        @SGaist having used layouts extensively in my application, I’m yet to find any properties of any layout which would allow me to achieve the above.

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

          If you want very specific sizes like that then you have to implement that yourself. Layouts try to make the best with whatever is available at runtime suiting the platform you are running on.

          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
          3
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            You could implement your own custom widget
            http://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html
            that scales like that.
            Or simply use a function that directly sets the size of the buttons on/before show.
            Im pretty sure if u made a aspect ratio aware layout, it would be useful to to others.
            Its asked often. :)

            1 Reply Last reply
            1
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6

              See http://doc.qt.io/qt-5/highdpi.html and http://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/

              The easiest way, if you are not on Apple's devices, is: program for low resolution and add QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); before you call QApplication's constructor

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              2

              • Login

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