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. Adapt different display size?
QtWS25 Last Chance

Adapt different display size?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 974 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.
  • ahsan737A Offline
    ahsan737A Offline
    ahsan737
    wrote on last edited by
    #1

    Greetings,
    I have used this code to fit the GUI to different display sizes.
    It is working fine for widgets, but it has no effect on the font size. Is there any solution?

        qreal refDpi = 320;
        qreal refHeight = 1792;
        qreal refWidth = 1080;
        
        QRect rect = QGuiApplication::primaryScreen()->geometry();
        qreal height = qMax(rect.width(), rect.height());
        qreal width = qMin(rect.width(), rect.height());
    
        qreal dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch();
        qreal m_ratio1 = qMin(height/refHeight, width/refWidth);
        qreal m_ratioFont1 = qMin(height*refDpi/(dpi*refHeight), width*refDpi/(dpi*refWidth));
    
        m_ratioFont = static_cast<int>(m_ratioFont1);
        m_ratio = static_cast<int>(m_ratio1);
    
    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      looks like you are calculating the font size based on display geometry but are you actually creating a font, setting its metrics, and making it the active font? Your code above stops short of that.

      ahsan737A 1 Reply Last reply
      0
      • Kent-DorfmanK Kent-Dorfman

        looks like you are calculating the font size based on display geometry but are you actually creating a font, setting its metrics, and making it the active font? Your code above stops short of that.

        ahsan737A Offline
        ahsan737A Offline
        ahsan737
        wrote on last edited by ahsan737
        #3

        @kent-dorfman said in Adapt different display size?:

        but are you actually creating a font, setting its metrics, and making it the active font? Your code above stops short of that.

        Can you please help me with some example code? I didn't quite understand it.

        I have tried to implement by calling these functions while setting widget and font size. It works for widget size, but font size remains unchanged (Qt designer default value).

            int applyFontRatio(const int value)
            {
                return int(value * m_ratioFont);
            }
        
            int applyRatio(const int value)
            {
                return qMax(2, int(value * m_ratio));
            }
        
        Pl45m4P 1 Reply Last reply
        0
        • ahsan737A ahsan737

          @kent-dorfman said in Adapt different display size?:

          but are you actually creating a font, setting its metrics, and making it the active font? Your code above stops short of that.

          Can you please help me with some example code? I didn't quite understand it.

          I have tried to implement by calling these functions while setting widget and font size. It works for widget size, but font size remains unchanged (Qt designer default value).

              int applyFontRatio(const int value)
              {
                  return int(value * m_ratioFont);
              }
          
              int applyRatio(const int value)
              {
                  return qMax(2, int(value * m_ratio));
              }
          
          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @ahsan737

          How do you set the font size?


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          ahsan737A 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @ahsan737

            How do you set the font size?

            ahsan737A Offline
            ahsan737A Offline
            ahsan737
            wrote on last edited by
            #5

            @Pl45m4 I have tried this way.

                Screen_Size size;    
                QFont font("SimSun",size.applyFontRatio(22), QFont::Normal, Qt::AlignVCenter);
                ui->label->setText("FBC");
                ui->label->setFont(font);
            
            Pl45m4P 1 Reply Last reply
            0
            • ahsan737A ahsan737

              @Pl45m4 I have tried this way.

                  Screen_Size size;    
                  QFont font("SimSun",size.applyFontRatio(22), QFont::Normal, Qt::AlignVCenter);
                  ui->label->setText("FBC");
                  ui->label->setFont(font);
              
              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @ahsan737 said in Adapt different display size?:

              QFont font("SimSun",size.applyFontRatio(22), QFont::Normal, Qt::AlignVCenter);

              Are you sure, that the "SinSun"-font is accessible by Qt?


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              ahsan737A 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @ahsan737 said in Adapt different display size?:

                QFont font("SimSun",size.applyFontRatio(22), QFont::Normal, Qt::AlignVCenter);

                Are you sure, that the "SinSun"-font is accessible by Qt?

                ahsan737A Offline
                ahsan737A Offline
                ahsan737
                wrote on last edited by
                #7

                @pl45m4 yes, I think it is the default font.

                Pl45m4P 1 Reply Last reply
                0
                • ahsan737A ahsan737

                  @pl45m4 yes, I think it is the default font.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #8

                  @ahsan737

                  Which OS are you using?

                  This (https://docs.microsoft.com/en-us/typography/font-list/simsun) says, that it's included in Win 8, but Win10 is not listed there...
                  If you are on Win10, maybe the font is not installed actually. This would explain, why you still see the Qt-Default font :)


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  ahsan737A 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @ahsan737

                    Which OS are you using?

                    This (https://docs.microsoft.com/en-us/typography/font-list/simsun) says, that it's included in Win 8, but Win10 is not listed there...
                    If you are on Win10, maybe the font is not installed actually. This would explain, why you still see the Qt-Default font :)

                    ahsan737A Offline
                    ahsan737A Offline
                    ahsan737
                    wrote on last edited by ahsan737
                    #9

                    it's done. I was missing this trick. Font ratio was 0 for my device so it was applying default value.

                    if (m_ratioFont < 1.) {
                        m_ratioFont = 1;
                    
                    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