[关闭]
@leaveye 2018-02-07T12:37:14.000000Z 字数 1586 阅读 887

项目 w1801 问题与解决

FAQ w1801


目录

应用安装类

QT 应用程序包在安装后看不到文字

来自 http://amin-ahmadi.com/2016/09/23/qt-application-fonts-missing-or-invisible-in-linux-fixed/

First create a Qt Resource file and add your font into it.

Let’s assume that our font is Ubuntu’s default Ubuntu-R.ttf file, then we need to add the following into our main.cpp

  1. QFontDatabase::addApplicationFont(“://Ubuntu-R.ttf”);
  2. qApp->setFont(QFont(“Ubuntu”, 11, QFont::Normal, false));

You should have your fonts back.

来自 https://stackoverflow.com/a/12179548

two possible solution: [^so12179548]

  1. pack with your application a font as a resource file, this way all platforms will use that font regardless the current systems default font.

  2. The QFont class has a method called defaultFamily(). Using this you could manually set the default font for your whole QApplication.

An example (main method):

  1. QApplication application(argc, argv);
  2. QFont font;
  3. font.setFamily(font.defaultFamily());
  4. application.setFont(font);
  5. ...rest of your code...

来自 https://forum.qt.io/post/436887

i advice for you one way for your question: Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?

It is a example, how to install the font for our application:

  1. int id = QFontDatabase::addApplicationFont(":/SMSicons/segoeui_0.ttf");
  2. QString family = QFontDatabase::applicationFontFamilies(id).at(0);
  3. QFont _font(family, 8);
  4. qApp->setFont(_font);
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注