Skip to content

Improve legibility of text esp. in screenshots. - #5113

Merged
gzotti merged 19 commits into
masterfrom
fix/screenshot-infotextbackground
Sep 18, 2026
Merged

gzotti merged 19 commits into
masterfrom
fix/screenshot-infotextbackground

Conversation

@gzotti

@gzotti gzotti commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Description

@sushoff asked me to investigate options for clearer screenshot printing.

Here are attempts to add additional darkness behind the Infotext.

  1. make the dropshadow configurable: blur radius and opacity are now configurable. However, The drop shadow just won't get really dark and large.
  2. set the HTML with dark background. But there are issues with Qt's HTML rendering.

found:

  • HTML font tag is actually ~20 years deprecated. use style attributes instead.
  • background color can only be set by a div/span combination,
  • table font and background color 'inherit' does not work

Ideas:

  • Use dark background only for night screenshots (logic from daylight text color)
  • GUI switch vs. config.ini?

This needs some care also with our Infotext postprocessing etc.

Fixes # (issue)

Screenshots (if appropriate):

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • This change requires a documentation update
  • Housekeeping

How Has This Been Tested?

Test Configuration:

  • Operating system: Win11
  • Graphics Card: Geforce, but should not matter

Checklist:

  • My code follows the code style of this project.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (header file)
  • I have updated the respective chapter in the Stellarium User Guide
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

found:
- HTML font tag is 20 years deprecated. use style attributes instead.
- background color can only be set by a div/span combination,
- table font color 'inherit' does not work
@gzotti gzotti added this to the 26.4 milestone Sep 14, 2026
@gzotti gzotti self-assigned this Sep 14, 2026
@gzotti gzotti added the enhancement Improve existing functionality label Sep 14, 2026
@gzotti gzotti added this to GUI Sep 14, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in GUI Sep 14, 2026
@github-actions
github-actions Bot requested review from 10110111 and alex-w September 14, 2026 16:49
@github-actions

Copy link
Copy Markdown

Great PR! Please pay attention to the following items before merging:

Files matching src/**/*.cpp:

  • Are possibly unused includes removed?

Files matching guide/**:

  • Did you remember to update screenshots to match new updates?
  • Did you remember to grammar check in changed part of documentation?

This is an automatically generated QA checklist based on modified files.

@github-actions

Copy link
Copy Markdown

Hello @gzotti!

Thank you for the suggested improvement.

@alex-w alex-w added the subsystem: gui The issue is related to GUI subsystem of planetarium... label Sep 14, 2026
- override colors not forwarded yet.
They only reimplemented the base implementation.
@gzotti

gzotti commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

I face a problem in that text color attributes are swallowed by Qt's rendering of HTML tables. These need dedicated CSS attributes color and (where needed) background-color, so the colors will be set several times.
StelObject::getInfoColor() and overrides will need to consult StelCore which would be allowed to override the object colors with forced or daylight colors. A problem is the occasional mix/misuse of labelColor and InfoColor, this may switch some colors.
A technical issue is the darkened background. Here I think the easiest approach is changing getInfoColor to return a Vec4f with the last element influencing opacity of the text background. In its "daylight" analysis, StelCore could decide (if user wants) to set a darkened background for night screenshots.
Another issue is stripping away color when InfoString::noFont is requested. (This was obviously named after the long-deprecated font tag that enclosed the HTML and should probably be renamed noColor.) So, instead of not adding the font/color group, we just need to strip out the CSS color style tags via regex.

@10110111

Copy link
Copy Markdown
Contributor

Why do you even define the style inline when you could define a bunch of classes in a separate CSS file and give the elements the class name? E.g. instead of

<table style='margin:0em 0em 0em -0.125em;border-spacing:0px;border:0px;color:%1;'>

you'd use

<table class='info-string'>

and have this in the common CSS:

.info-string {
    margin: 0em 0em 0em -0.125em;
    border-spacing: 0px;
    border: 0px;
    color: #YOURCOLOR;
}

@gzotti

gzotti commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Thanks. The inline CSS was already here, so I just expanded it. I am actually not familiar with interacting with external CSS: The YOURCOLOR will have to change during infostring generation/before display. How would I set this? In addition, the HTML surrounding the tables also needs the color/background. (This is now done by the span element)

@10110111

Copy link
Copy Markdown
Contributor

Looks like you can set the style sheet for InfoPanel using document()->setDefaultStyleSheet(css);. This should be done before calling setHtml(infoHTML), it won't apply to the existing text.

As for YOURCOLOR, you can use a %1-style placeholder for it in the common CSS, and replace it before applying this CSS. This will be the single place you ever define this color.

Color in named elements work. Unclassified text still has no color.

Back to wrapping in font tags?
@10110111

Copy link
Copy Markdown
Contributor

Unclassified text still has no color.
Back to wrapping in font tags?

What kind of text? Something out of any tags? Maybe you could wrap such text in <p class=...> or <span class=...>?

@gzotti

gzotti commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Yes, I reactivated the div class=.... However, the background-color is not used. Apart from that it seems to work now.

- also deactivated unused css elements for now
- it seems background-color is still not working outside tables.
Comment thread src/gui/StelGui.cpp Outdated
Comment thread src/core/modules/Planet.cpp Outdated
@gzotti gzotti modified the milestones: 26.4, 26.3 Sep 16, 2026
Comment thread src/gui/StelGui.cpp Outdated
@alex-w

alex-w commented Sep 17, 2026

Copy link
Copy Markdown
Member

I hope copying data via clipboard is still alive?

@gzotti

gzotti commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

I hope copying data via clipboard is still alive?

Of course. I tested both types, HTML in LibreOffice and plaintext in a text editor.

@gzotti

gzotti commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

Any more comments/additions?

@10110111

Copy link
Copy Markdown
Contributor

The title background appears to be too wide:

stellarium-021

@10110111

Copy link
Copy Markdown
Contributor

Negative opacity fails to change the text color, leaving it unreadable:

stellarium-022

@10110111

Copy link
Copy Markdown
Contributor

The title background appears to be too wide

There's an interesting way to combat this, but there is a drawback. The patch:

diff --git a/src/gui/SkyGui.cpp b/src/gui/SkyGui.cpp
index 534a28096c..9b9c44f4f0 100644
--- a/src/gui/SkyGui.cpp
+++ b/src/gui/SkyGui.cpp
@@ -31,6 +31,7 @@
 #include <QTimeLine>
 #include <QGraphicsSceneMouseEvent>
 #include <QSettings>
+#include <QTextCursor>
 #include <QTextDocument>
 #include <QRegularExpression>
 #include <QGraphicsDropShadowEffect>
@@ -101,18 +102,15 @@ void InfoPanel::setTextFromObjects(const QList<StelObjectP>& selected)
         static const QString css(
             "h2 {"
                   "color: %1;"
-                  "background-color: rgba(0,0,0,%2%);"
                 "} "
             ".info-string {"
                   "color: %1;"
-                  "background-color: rgba(0,0,0,%2%);"
                 "} "
             "table.info-string {"
                   "margin: 0em 0em 0em -0.125em;"
                   "border-spacing: 0px;"
                   "border: 0px;"
                   "color: %1;"
-                  "background-color: rgba(0,0,0,%2%);"
                 "} ");
 
         // just print details of the first item for now
@@ -120,7 +118,7 @@ void InfoPanel::setTextFromObjects(const QList<StelObjectP>& selected)
         StelCore *core=StelApp::getInstance().getCore();
 
         Vec3f color = selected[0]->getInfoColor();
-        QString opacity=QString::number(this->opacity);
+        int bgAlpha = this->opacity * 255 / 100;
         if (StelApp::getInstance().getFlagOverwriteInfoColor())
         {
             // make info text more readable...
@@ -130,21 +128,27 @@ void InfoPanel::setTextFromObjects(const QList<StelObjectP>& selected)
         {
             // make info text more readable when atmosphere enabled at daylight.
             color = StelApp::getInstance().getDaylightInfoColor();
-            opacity="0";
+            bgAlpha = 0;
         }
         // A negative opacity forces dark background even for daylight scenes.
         if (this->opacity<0)
-            opacity=QString::number(qAbs(this->opacity));
+            bgAlpha = qAbs(this->opacity) * 255 / 100;
 
         infoHTML = selected[0]->getInfoString(core, infoTextFilters);
         selected[0]->removeExtraInfoStrings(StelObject::AllInfo);
 
-        document()->setDefaultStyleSheet(css.arg(color.toHtmlColor(), opacity));
+        document()->setDefaultStyleSheet(css.arg(color.toHtmlColor()));
 
         // We need the span to set the background opacity.
-        setHtml(QString("<div class='info-string'><span style='background:rgba(0, 0, 0, %1%);'>").arg(opacity)
-            + infoHTML
-            + "</span></div>");
+        setHtml("<div class='info-string'>"
+             + infoHTML
+             + "</div>");
+        QTextCursor cursor(document());
+        cursor.setPosition(0);
+        cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
+        QTextCharFormat fmt;
+        fmt.setBackground(QColor(0,0,0, bgAlpha));
+        cursor.mergeCharFormat(fmt);
     }
 }
 

The drawback: for some reason <b> and </b> result in "vertical line" artifacts when |opacity| is not 100%:

stellarium-023

@gzotti

gzotti commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

The title background appears to be too wide:

I have seen it. But I have no idea what to do here.

The requested-for application of this manual-only setting is to create more legible screenshots at night, i.e., to cover stars and other sky elements in the text area. For daylight screenshots, you must obviously use "override text color" and set a daylight color other than black. I don't fight any 'black on black' situation the user can mitigate. The daylight application (negative opacity) is ugly to begin with and I don't know if anybody ever would use it (It may help visually impaired, though), but was easy to add.

@gzotti

gzotti commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

QTextCursor cursor(document());

Interesting hack. But it's a new hack, not what I call elegant.
Maybe the h2 issue stems from the rtl/ltr settings that might extend the width to the maximum width of the infoPanel. Would setting the background inside a span within the rtl/ltr clauses help? Does it really matter?

@10110111

Copy link
Copy Markdown
Contributor

Maybe the h2 issue stems from the rtl/ltr settings that might extend the width to the maximum width of the infoPanel. Would setting the background inside a span within the rtl/ltr clauses help?

I think the header takes the whole width regardless of rtl/ltr settings. The styled span inside the header (with unstyled header) should fix it, though I didn't check.

Does it really matter?

It's a matter of completeness of the feature.

@gzotti

gzotti commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

I played around with defining spans inside the Planet::getInfoLabel() and other attempts that could have helped assuming the rtl/ltr cause. Seems not to help. But I also saw how broken the whole InfoString looks in Arab!

At this point I declare the long dark title bar a feature. Currently this PR feature has one user.

@10110111

Copy link
Copy Markdown
Contributor

Hmm, something strange is going on. I have black text on black background even during the night with the following settings:

info_panel_opacity                              = -100
info_shadow_opacity                             = 0
info_shadow_radius                              = 20
stellarium-022

@gzotti

gzotti commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

With the latest commit?

@10110111

Copy link
Copy Markdown
Contributor

Tested with 015e1c6. Before it there was no such issue.

@gzotti

gzotti commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

Alright, my daylight color is yellow, yours is black. Now I hope your OverwriteColor is not black.

@10110111

Copy link
Copy Markdown
Contributor

Alright, my daylight color is yellow, yours is black. Now I hope your OverwriteColor is not black.

The question is not what "my" colors are, but rather what the defaults are. I don't remember to have changed colors.

At least, with the latest commit things seem to look OK.

@gzotti
gzotti merged commit 75587ab into master Sep 18, 2026
30 of 31 checks passed
@gzotti
gzotti deleted the fix/screenshot-infotextbackground branch September 18, 2026 18:19
@github-project-automation github-project-automation Bot moved this from Backlog to Done in GUI Sep 18, 2026
@youlaafifah

Copy link
Copy Markdown
Contributor

Dear @gzotti.

This feature is really amazing. I have tried it, but it is not working for the legend. When I click the general body like planets, or stars, those are fine. But not with the legend. Here is from my screenshot
stellarium-024

@gzotti

gzotti commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Uh, OK. I should probably add a span style somewhere, Qt is quite picky about which HTML is affected by CSS. Sorry, will be in 26.4 (or earlier beta).

@youlaafifah

Copy link
Copy Markdown
Contributor

Thank you

gzotti added a commit that referenced this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve existing functionality subsystem: gui The issue is related to GUI subsystem of planetarium...

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants