Adapt different display size?
-
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);
-
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.
-
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.
@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)); }
-
@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)); }
-
@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);
-
@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?
-
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 :) -
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 :)