Solved Most widgets obscured, covered up by black
-
(Sorry to be monopolising this forum.)
This is a strange one. The application that I'm porting from Windows to Linux is basically working now (as long as it is invoked in a terminal). But all the input screens are displayed with a flood of black that covers up most (but strangely not all) of the field labels. The situation is best conveyed by screenshots - the two attached pics are for one of the input screens,
with Linux
,and with Windows:
The screen widget (tab_run) has this location in Designer:
MainWQindow (QMainWindow)
----centralWidget (QWidget)
--------stackedWidget (QStackedWidget)
------------tabs (QTabWidget)
----------------tab_run (QWidget)(There is a misalignment issue with the field labels, but that is just a font size issue.)
-
@gibbogle this seems to me like a stylesheet issue. Do you use stylesheets and do you set the background-color for any of your widgets?
I would guess no :)
-
Hi,
To add to @J-Hilk, what desktop environment are you using on Linux ? Does it have a dark theme ?
Are you using the distribution provided Qt ? -
@j-hilk
I don't know anything about stylesheets, and don't (knowingly) use them.
No, I don't set a background color for any widgets.Edit: I should mention that it is only on the tabs member screens that this problem occurs. The other widgets that are members of stackedWidget do not have this problem.
-
@sgaist
Whatever desktop environment I'm using is that which comes with Ubuntu 18.04, by default. I just installed 18.04 a few days ago and have changed nothing. How do I find out about my desktop environment?
The Qt distribution is that installed by:
qt-opensource-linux-x64-5.13.0.run -
@j-hilk
I found some helpful suggestions, and did this in main.cpp:mainWin.showMaximized(); //specify a new font. QFont newFont("Helvetica", 10, QFont::Normal, false); //set font of application QApplication::setFont(newFont); foreach (QWidget *widget, QApplication::allWidgets()) { widget->setFont(QApplication::font()); widget->setStyleSheet("background-color:white;"); widget->update(); }
and this has solved the black problem!
The alignment and sizing of many widgets is a bit different from in Windows, and requires some adjustments, but that's a relatively trivial issue.The global setting of widget fonts like this is effective, but not ideal, since it overrides any wanted variations introduced in Design. I guess what I really want is to scale the widget fonts globally - is that possible?
-
Not necessarily how I would have done it, but hey it works 😉
Don't forget to set the topic via topic tools to solved!
Happy coding -
@j-hilk
Feel free to suggest a better way. Any suggestions about how to reduce the font size while preserving, for example, the distinction between bold (e.g. titles) and normal text? -
@gibbogle
well, take a look at the high dpi display page of the documentation
https://doc.qt.io/qt-5/highdpi.htmlUseful to read anyway.
What you're looking for is probably
QT_SCALE_FACTOR
which effects all fonts, scaled.It's an environment variable an can be set inside your code
qputenv("QT_SCALE_FACTOR", "1.5");
-
@j-hilk
Excellent! Just what I wanted. Thanks a lot.
Everything is working now, except that I can't trigger the execution within Qt Creator.