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
@@ -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