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. Scale Size of all GUI Widgets easily?

Scale Size of all GUI Widgets easily?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 25.2k Views
  • 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.
  • C Offline
    C Offline
    CAD_coding
    wrote on 23 Apr 2013, 07:32 last edited by
    #1

    Hi,
    I have been developing an application while learning Qt.
    What I did was I hard coded the size of Widgets according what seemed good on my Laptop.
    Now I think that it might not be good idea, because if my user has a different screen resolution then the application will look different from what was intended.
    Now I know how to get the size of the user's screen resolution by QRect QDesktopWidget::availableGeometry().
    Now I can create scaling factors for height & width by:
    @hScale = (user's screen height) / (my screen height);
    wScale = (user's screen width) / (my screen width);@

    Now I wanted to know whether it is possible to apply these scales globally on all widgets by some function?
    Since I have created widgets in many classes & also with .ui file it would be very tedious to manually change the dimensions fo reach widget.
    Any way to simplify my problem?
    Thank You.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 Apr 2013, 10:28 last edited by
      #2

      what is exactly your use case?!

      You should use "QLayouts":http://qt-project.org/doc/qt-4.8/layout.html which are handle the resizing of all child widgets for you. Then you can still restrict the size of your top level widget (e.g. the main window).

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CAD_coding
        wrote on 24 Apr 2013, 04:58 last edited by
        #3

        @raven-worx Yes I have used Layout's. But I hard coded the minimum size for some widgets like PushButton, ComboBox, etc.
        How do I solve my problem then?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on 24 Apr 2013, 06:03 last edited by
          #4

          if it is minimumSize then you can just leave it at that and just set your main windows size according to the availableGeometry and the widgets should expand to keep their look

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on 24 Apr 2013, 06:59 last edited by
            #5

            You could go through all widgets with
            @QApplication::allWidgets()@
            and scale their minimum sizes accordingly. Make sure you test your UI for all realistic scale factors that will ever be used.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              CAD_coding
              wrote on 24 Apr 2013, 08:37 last edited by
              #6

              Hi DerManu I think that will solve my problems. But a few questions here:

              1. When should I call this function in my application at startup?
              2. What if widgets are added after calling this function?
              3. If I have to call this function every time I edit the GUI, then is there some way by which I can skip those widgets that are already scaled?
              4. Is this method efficient, in terms of time & computation?
                Thank You.
              1 Reply Last reply
              0
              • R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 24 Apr 2013, 08:48 last edited by
                #7

                [quote author="CAD_coding" date="1366792630"]1. When should I call this function in my application at startup?[/quote]
                on every resize of your mainwindow.

                [quote author="CAD_coding" date="1366792630"]2. What if widgets are added after calling this function?[/quote]
                so they are not included in the list at the time it is called.

                [quote author="CAD_coding" date="1366792630"]3. If I have to call this function every time I edit the GUI, then is there some way by which I can skip those widgets that are already scaled?[/quote]
                you could set a dynamic (int) property on the widgets which increases on every iteration.

                [quote author="CAD_coding" date="1366792630"]4. Is this method efficient, in terms of time & computation?[/quote]
                No it's not... depending at the number of widgets you have in your application. But in general your approach is bad design IMHO.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DerManu
                  wrote on 24 Apr 2013, 09:32 last edited by
                  #8

                  By the way, you do know about horizontal/vertical scale factors for widgets in layouts? Kind of sounds like you're trying to reinvent the wheel a bit. I do see the necessity to have different parameters for very different screen sizes, but continuously modifying the minimum size on every resize event of the main window, sounds like there is something wrong. Scalefactors might do something similar for you, without the hackery.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrX2yyZaD6
                    wrote on 27 Aug 2019, 14:10 last edited by
                    #9

                    I have a Qt application where I sometime need to rescale (as opposed to resizing using layouts) all the widgets for screens of different
                    display resolution. I did a tree walk of every widget and adjusted the minimum size, the maximum size, the current size and the font size
                    for each widget. Other widgets got special attention, such as the indent for a QLabel widgets. The scaling could be a one off application
                    wide scaling or more dynamic and applied to an individual form (in response to ctrl/+ and ctrl/- like most browsers).
                    In order not to accumulate scaling errors, the original size values are saved in a dynamic property associated with each widget.
                    For application wide scaling, the scaling is applied after each ui file is loaded or widget created.

                    Have a look at https://github.com/qtepics/qeframework/blob/master/qeframeworkSup/project/common/QEScaling.h and .cpp file.
                    It would not take much effort to decouple this class to make stand alone.

                    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