Linux + Qt + QLineEdit + TTF = Nightmare
-
I am currently using Qt 4.8.6 on RHEL 7.1
When I try and use my TFF font for my QLineEdit, my font is getting substituted with something default. On Windows everything works great, but on Linux...
Any assistance would be GREATLY appreciated.
THANKS!
-
Hi @QtAndLinux
How are you using your font with QLineEdit?
Is it with stylesheet?
you can add your font like this, for me i prefer add things like this in main.cpp :
QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
After that with Qt stylesheet you can set font of your QLineEdit
QLineEdit{ ... font-family: your_font_name; // here add your font without .ttf ... }
I tested this a lot of time with my Qt applicatiojn and it worked without without any problem
-
Hi @QtAndLinux
How are you using your font with QLineEdit?
Is it with stylesheet?
you can add your font like this, for me i prefer add things like this in main.cpp :
QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
After that with Qt stylesheet you can set font of your QLineEdit
QLineEdit{ ... font-family: your_font_name; // here add your font without .ttf ... }
I tested this a lot of time with my Qt applicatiojn and it worked without without any problem
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
Hi @QtAndLinux
How are you using your font with QLineEdit?
Is it with stylesheet?
you can add your font like this, for me i prefer add things like this in main.cpp :
QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
After that with Qt stylesheet you can set font of your QLineEdit
QLineEdit{ ... font-family: your_font_name; // here add your font without .ttf ... }
I tested this a lot of time with my Qt applicatiojn and it worked without without any problem
Currently I am not using stylesheets.
To set the font I've tried:
- Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
- Add the font to the QFontDatabase and then use QLineEdit.setFont
If I check the QFontDatase, my font is there and I can get the family, style and sizes...
UPDATE
Added a stylesheet:- I can set the text color
- I can set the background color
- Still can't set the font
-
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
Hi @QtAndLinux
How are you using your font with QLineEdit?
Is it with stylesheet?
you can add your font like this, for me i prefer add things like this in main.cpp :
QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
After that with Qt stylesheet you can set font of your QLineEdit
QLineEdit{ ... font-family: your_font_name; // here add your font without .ttf ... }
I tested this a lot of time with my Qt applicatiojn and it worked without without any problem
Currently I am not using stylesheets.
To set the font I've tried:
- Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
- Add the font to the QFontDatabase and then use QLineEdit.setFont
If I check the QFontDatase, my font is there and I can get the family, style and sizes...
UPDATE
Added a stylesheet:- I can set the text color
- I can set the background color
- Still can't set the font
@QtAndLinux said in Linux + Qt + QLineEdit + TTF = Nightmare:
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
Hi @QtAndLinux
How are you using your font with QLineEdit?
Is it with stylesheet?
you can add your font like this, for me i prefer add things like this in main.cpp :
QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
After that with Qt stylesheet you can set font of your QLineEdit
QLineEdit{ ... font-family: your_font_name; // here add your font without .ttf ... }
I tested this a lot of time with my Qt applicatiojn and it worked without without any problem
Currently I am not using stylesheets.
To set the font I've tried:
- Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
- Add the font to the QFontDatabase and then use QLineEdit.setFont
If I check the QFontDatase, my font is there and I can get the family, style and sizes...
UPDATE
Added a stylesheet:- I can set the text color
- I can set the background color
- Still can't set the font
Hi again , after few search i think that is is what you need to do
int id =QFontDatabase::addApplicationFont(":/path_to_your_font/your_font_family.ttf"); QString customFontFamilyName = QFontDatabase::applicationFontFamilies(id).at(0); qDebug() << customFontFamilyName;// this will give the exact name of the font
you can set font of qlineedit like this:
QFont customFont; customFont.setFamily(customFontFamilyName); ui->lineEdit->setFont(customFont);
or in stylesheet:
QLineEdit { font-family: customFontFamilyName; }
Try and keep me informed !
-
@QtAndLinux said in Linux + Qt + QLineEdit + TTF = Nightmare:
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
Hi @QtAndLinux
How are you using your font with QLineEdit?
Is it with stylesheet?
you can add your font like this, for me i prefer add things like this in main.cpp :
QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
After that with Qt stylesheet you can set font of your QLineEdit
QLineEdit{ ... font-family: your_font_name; // here add your font without .ttf ... }
I tested this a lot of time with my Qt applicatiojn and it worked without without any problem
Currently I am not using stylesheets.
To set the font I've tried:
- Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
- Add the font to the QFontDatabase and then use QLineEdit.setFont
If I check the QFontDatase, my font is there and I can get the family, style and sizes...
UPDATE
Added a stylesheet:- I can set the text color
- I can set the background color
- Still can't set the font
Hi again , after few search i think that is is what you need to do
int id =QFontDatabase::addApplicationFont(":/path_to_your_font/your_font_family.ttf"); QString customFontFamilyName = QFontDatabase::applicationFontFamilies(id).at(0); qDebug() << customFontFamilyName;// this will give the exact name of the font
you can set font of qlineedit like this:
QFont customFont; customFont.setFamily(customFontFamilyName); ui->lineEdit->setFont(customFont);
or in stylesheet:
QLineEdit { font-family: customFontFamilyName; }
Try and keep me informed !
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
Hi again , after few search i think that is is what you need to do
int id =QFontDatabase::addApplicationFont(":/path_to_your_font/your_font_family.ttf"); QString customFontFamilyName = QFontDatabase::applicationFontFamilies(id).at(0); qDebug() << customFontFamilyName;// this will give the exact name of the font
you can set font of qlineedit like this:
QFont customFont; customFont.setFamily(customFontFamilyName); ui->lineEdit->setFont(customFont);
or in stylesheet:
QLineEdit { font-family: customFontFamilyName; }
Try and keep me informed !
First of all, thank you very much for the help!
Tried adding the font to the QFontDatabase:
- The font gets added to the QFontDatabase
- The exact name of the font is what I was using previously
- Used setFont to set the QLineEdit font, but it is still not showing my TTF
- If I ui->lineEdit->font() exactMatch() is true and family() is set to customFontFamilyName
Tried using the stylesheet:
- QLineEdit font is still not showing my TTF but text and background color are both set
-
This is really strange, except changing font are doing something else on your parent Widget?
Is there any sample code that you could share with us?
-
This is really strange, except changing font are doing something else on your parent Widget?
Is there any sample code that you could share with us?
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
This is really strange, except changing font are doing something else on your parent Widget?
Is there any sample code that you could share with us?
This is VERY strange. All of this works fine in Windows, but in Linux the QlineEdit just won't show the TTF.
Here is my code without stylesheet:
int retCode = QFontDatabase::addApplicationFont(":/fonts/resources/pleasework.ttf"); QString customFontFamilyName = QFontDatabase::applicationFontFamilies(retCode).at(0); qDebug() << customFontFamilyName;// this will give the exact name of the font QFont customFont; customFont.setFamily(customFontFamilyName); ui.Input->setFont(customFont);
Here is my code with a stylesheet:
int retCode = QFontDatabase::addApplicationFont(":/fonts/resources/pleasework.ttf"); app.setStyleSheet("QLineEdit { background: yellow; font-family: pleasework; }");
-
Your code seems good,
I am out of idea , did you try with another font.ttf ?
Maybe the problem is due to this font on linux, could you test with another font?
@mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:
Your code seems good,
I am out of idea , did you try with another font.ttf ?
Maybe the problem is due to this font on linux, could you test with another font?
"FontAwesome" and "LKLUG" have the same problem:
- Font Viewer shows the font without any problems
- When I try use the font with a QLineEdit it gets replaced
Do "FontAwesome" and "LKLUG" work for your QLineEdit?
-
I am not having these fonts on my UBUNTU,
What about other fonts(except "FontAwesome" and "LKLUG") , they work without any problem?