PDA

View Full Version : Increase font size globally (and proportionally)



quimnuss
2nd September 2015, 16:05
My application has two 'modes' of functioning, touchscreen and desktop. For the touchscreen mode, I would need to make everything bigger: fonts, icons, buttons, etc. Is there a way to achieve that?

I have a slider that could change the stylesheet of the application, but I don't know how to make everything scale proportionally. I've successfully changed a checkbox, icon size and font size of a QListView by changing the stylesheet according to a slider value, but I actually would need to make those changes everywhere in the application.

If not through a slider, making two fixed configurations would work too, but I don't know how to change the base font size globally so that everything is proportional to this base font.

Charvi
3rd September 2015, 10:50
You could apply the stylesheet to the whole application by using QApplication's setStyleSheet(const QString & sheet) method.

Please check:
http://stackoverflow.com/questions/11681943/qt-global-style-sheet-loading

quimnuss
3rd September 2015, 11:21
Good hint, Charvi.

I have an assert error when I add

app.setStyleSheet("QWidget{font-size:30px;}");

at ASSERT: "calledEmitUpdated" in file graphicsview\qgraphicsscene.cpp, line 467

What else other than QWidget should I use? Maybe QLabel is enough for text, but I would have to change also icon size and, also, slider size (!). How could I do that?

The problem with that approach is that the fonts are all set to those 30px, while in my application I have different sizes for different things. I guess the only solution is to make every font policy I set relative to that one to have different sizes, manually.

I'd have to add an icon-size as well.

Added after 15 minutes:

Setting the StyleSheet on the MainWindow solves the assert issue, and since I have all the hierarchy parented, using QWIdget font-size works.

The only trouble then is that all proportions are lost.

newcfd
4th September 2015, 22:16
you can do the following:
QFont new_font = app.font();
new_font.setPointSize( int ** ); //your option
new_font.setWeight( int ** ); //your option
app.setFont( new_font );

quimnuss
9th September 2015, 12:26
Nice to know!

It would have the same problem as the other approaches but circumvents the use of stylesheets (If I didn't want to).

Cheers