fix(ui): stop the platform from drawing a light band around menus
The stylesheet colours a QMenu, but a dropdown is its own native window: the margin the platform leaves around it is not part of the widget the stylesheet paints, and it is filled from the application palette. Left at the desktop default, that margin shows as a white band above and below the menu on a light theme. Giving the palette the window's own surface colour covers it, and has the useful side effect of dragging tooltips and popups onto the dark theme too. The colours are the same tokens as the stylesheet, spelled as palette roles: Qt 6 has no Menu role left, and Window is what the popup margin uses.
This commit is contained in:
4 files changed
+59
No files matched your search
@@ -150,6 +150,13 @@ L'apparence reprend le **design system du site FWS**
|
||||
est appliquée à la fenêtre (`appStyleSheet()` dans `src/main-window.cpp`) : un
|
||||
fichier d'écran ne décrit que sa mise en page et son texte, jamais ses couleurs.
|
||||
|
||||
Une exception : les menus déroulants. Un `QMenu` est une **fenêtre native
|
||||
séparée**, et la marge que la plateforme dessine autour (l'ombre du popup) n'appartient
|
||||
pas au widget que la feuille de style dessine — elle est remplie depuis la
|
||||
palette de l'application. Sans palette sombre, elle ressort en bande **blanche en
|
||||
haut et en bas** du menu sur un thème clair. D'où `MainWindow::appPalette()`,
|
||||
appliquée dans `main()` avant tout widget.
|
||||
|
||||
### Tokens
|
||||
|
||||
| Rôle | Valeur | Usage |
|
||||
@@ -200,6 +207,7 @@ de style ne fait que fixer la couleur du texte.
|
||||
| Besoin | Endroit |
|
||||
| --- | --- |
|
||||
| Une couleur, une bordure, un rayon | `appStyleSheet()` dans `src/main-window.cpp`. |
|
||||
| Ce que la feuille de style n'atteint pas (marge des menus déroulants, ombres de popup) | `MainWindow::appPalette()`, appliquée dans `main.cpp`. Même tableau de tokens, mais en rôles de palette : Qt 6 n'a pas de rôle `Menu`, c'est `Window` qui remplit la marge du popup. |
|
||||
| Un badge, une pastille, un compteur | `pages/ui-kit.cpp`. |
|
||||
| Une couleur de statut dans une table | La page concernée (`QTableWidgetItem::setForeground`). |
|
||||
| Une icône | `resources/icons/*.svg` (le trait suit la couleur du texte). |
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QElapsedTimer>
|
||||
#include <QHash>
|
||||
#include <QMainWindow>
|
||||
#include <QPalette>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSystemTrayIcon>
|
||||
@@ -50,6 +51,10 @@ public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
// Colours the stylesheet cannot reach, applied in main() before any widget
|
||||
// exists. See the definition for what leaves a light band around a menu.
|
||||
static QPalette appPalette();
|
||||
|
||||
// Installs the Flatpak files handed over by the desktop: dropped on the
|
||||
// window, or opened from the file manager ("Ouvrir avec PacManager", which
|
||||
// passes them on the command line). One install runs at a time; the rest
|
||||
|
||||
@@ -324,6 +324,11 @@ static QString appStyleSheet() {
|
||||
" border-radius: 8px;"
|
||||
" padding: 6px;"
|
||||
"}"
|
||||
// The popup's own margin (the shadow the platform draws around it) is
|
||||
// not part of this widget: it is filled from the application palette,
|
||||
// which is why appPalette() has to carry the same surface colour. Left
|
||||
// alone it is the desktop's default, i.e. a light band above and below
|
||||
// the menu on a light theme.
|
||||
"QMenu::item { padding: 7px 24px 7px 14px; border-radius: 6px; }"
|
||||
"QMenu::item:selected { background: #21384e; color: #38bdf8; }"
|
||||
"QMenu::item:disabled { color: #64748b; }"
|
||||
@@ -358,6 +363,44 @@ static QString appStyleSheet() {
|
||||
"}");
|
||||
}
|
||||
|
||||
// Colours the stylesheet cannot reach.
|
||||
//
|
||||
// A QMenu is a separate native popup: only its inner widget is drawn by the
|
||||
// stylesheet, while the margin the platform leaves around it — the shadow — is
|
||||
// filled from the application palette. On a light desktop theme that margin is
|
||||
// white, which shows up as a light band above and below the menu. Giving the
|
||||
// palette the window's own surface colour makes the whole popup one colour.
|
||||
//
|
||||
// The values repeat appStyleSheet()'s on purpose: a palette is a set of roles,
|
||||
// not CSS, and there is no way to point one at a stylesheet. They must be kept
|
||||
// in step with the token table in doc/interface.md.
|
||||
QPalette MainWindow::appPalette() {
|
||||
const QColor window(0x1e, 0x29, 0x3b); // surface
|
||||
const QColor raised(0x27, 0x34, 0x49); // raised surface
|
||||
const QColor text(0xe2, 0xe8, 0xf0); // text
|
||||
const QColor muted(0x94, 0xa3, 0xb8); // secondary text
|
||||
const QColor accent(0x38, 0xbd, 0xf8); // accent
|
||||
|
||||
// Qt 6 has no separate Menu role, and that is exactly the point: the margin
|
||||
// a QMenu popup is drawn with is filled from Window, so this is the colour
|
||||
// that removes the light band.
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Window, window);
|
||||
palette.setColor(QPalette::WindowText, text);
|
||||
palette.setColor(QPalette::Base, raised);
|
||||
palette.setColor(QPalette::AlternateBase, window);
|
||||
palette.setColor(QPalette::Text, text);
|
||||
palette.setColor(QPalette::Button, raised);
|
||||
palette.setColor(QPalette::ButtonText, text);
|
||||
palette.setColor(QPalette::BrightText, Qt::white);
|
||||
palette.setColor(QPalette::ToolTipBase, raised);
|
||||
palette.setColor(QPalette::ToolTipText, text);
|
||||
palette.setColor(QPalette::Highlight, accent);
|
||||
palette.setColor(QPalette::HighlightedText, QColor(0x0f, 0x17, 0x2a));
|
||||
palette.setColor(QPalette::PlaceholderText, muted);
|
||||
return palette;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
m_core = new AppCore(this);
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ int main(int argc, char* argv[]) {
|
||||
app.setApplicationName("PacManager");
|
||||
app.setApplicationVersion(UpdateManager::currentVersion());
|
||||
app.setOrganizationName("Freebuff");
|
||||
// Before any widget exists: the palette is what the platform draws the
|
||||
// parts the stylesheet cannot reach, such as the margin around a menu.
|
||||
app.setPalette(MainWindow::appPalette());
|
||||
|
||||
// Every log category the app uses is enabled (qCDebug included) and funnelled
|
||||
// into the journal, so the Logs screen shows the same detail as a debug run
|
||||
|
||||
Reference in new issue
Block a user