Invisible text in QTextEdit
-
I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown.
int main(int argc, char *argv[]) { QApplication app(argc, argv); QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont); std::cout << font.toString().toUtf8().constData(); QFontDatabase database; QStringList fam = database.families(); app.setFont(QFont("Ubuntu", 11, QFont::Normal, false)); QTextEdit textEdit; textEdit.show(); return app.exec(); }
I tried to get system font using QFontDatabase but it didn't work:
app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
This doesn't do anything with any of enum values including QFontDatabase::GeneralFont
QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
font prints Sans Serif,9,-1,5,50,0,0,0,0,00.
QFontDatabase database; QStringList fam = database.families();
fam size is zero.
I built qt from source using the instructions here. How can I fix this and set the app font to default ubuntu font?
My specs:
Ubuntu 16.04
Qt 5.9.1 -
@Alp-Hancioglu Does it work if you don't set any font? Do other Qt apps work (like VCL)?
Also: how did you install Qt? -
It doesn't work if I don't set any font.
Do you mean VLC media player? I just installed VLC and it also doesn't display any text. It only displays window headers and menu items.
I built qt from source as I said in my post. -
Hmm.. according to your code:
When you do not set a text in the QTextEdit-Control (textEdit.setPlainText)
there will be no visible text in the control! -
@karlheinzreichel I don't understand what you mean exactly but textEdit.append("some"); call doesn't display any text either. It moves the cursor but no text is shown.
-
@Alp-Hancioglu
in your code above there is no append (or did I miss something ?) -
@karlheinzreichel I tried the append call at some point but forgot to add it to the post. The issue seems much more bigger than QTextEdit though as there is also no text shown in VLC media player.
-
As you build qt from scratch, the question :
Have you installed the libconfig libraries before ... ?(probably not)
regards
karl-heinz -
@karlheinzreichel I didn't explicitly install libconfig library myself. I don't know if other program installed it as prerequisite.
In order to build, I downloaded qt-everywhere-opensource-src-5.9.1.tar.xz file and extracted it.
Then called ./configure and make on bash. -
So I would reccomend to check the build requierments for QT
(see http://doc.qt.io/qt-5/linux-requirements.html)
before building the qt libsregards
Karl-Heinz -
@Alp-Hancioglu Try to start your app with QT_DEBUG_PLUGINS environment variable set and check the output in the console. Looks like something is wrong with your system.
-
@Alp-Hancioglu Are there any errors/warnings?
-
@karlheinzreichel I checked every package and its dev version listed in requirements list and they are all installed and at newest version so there is no need to install or upgrade any of them. Some packages don't have the exact same name on my machine: libfontconfig is listed as libfontconfig1 on mine, libfreetype is listed as libfreetype6 on mine but the descriptions match.
I built Qt a week ago so they were most probably at newest version at time of compilation so I don't think they are related to the issue I have. -
@Alp-Hancioglu If you execute configure script before building Qt you will get a summary what was found and enabled. You can execute configure again with -v parameter and see whether fontconfig was really enabled.
-
@jsulm Thanks for the continued support jsulm.
I used ./configure -v and saw that fontconfig is disabled in build options:
Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no
Then I used ./configure -v -fontconfig to enable it but it didn't work with error:
ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && !config.darwin && features.system-freetype && libs.fontconfig' failed.
Then I run following to make sure libfontconfig is installed:
sudo apt install libfontconfig1 [sudo] password for alp: Reading package lists... Done Building dependency tree Reading state information... Done libfontconfig1 is already the newest version (2.11.94-0ubuntu1.1). 0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
I also run ./configure -system-freetype -fontconfig but it doesn't make a difference with resulting errors:
ERROR: Feature 'system-freetype' was enabled, but the pre-condition 'features.freetype && libs.freetype' failed. ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && !config.darwin && features.system-freetype && libs.fontconfig' failed.
Make sure freetype is installed:
sudo apt install libfreetype6 Reading package lists... Done Building dependency tree Reading state information... Done libfreetype6 is already the newest version (2.6.1-0.1ubuntu2.3). 0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
-
@Alp-Hancioglu You need to install the dev package for fontconfig. Something like libfontconfig1-dev.
-
@jsulm It is already installed:
sudo apt install libfontconfig1-dev [sudo] password for alp: Reading package lists... Done Building dependency tree Reading state information... Done libfontconfig1-dev is already the newest version (2.11.94-0ubuntu1.1). 0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
I checked every dev package in the requirements list and they are all installed with newest versions
-
@Alp-Hancioglu If you execute configure with -v you should get more output. Can you post it here?