UI/Qt: Style the menu bar

Add a QMenuBar stylesheet that uses the same chrome palette as the tab
strip and navigation toolbar. Apply it from BrowserWindow and refresh it
when the palette changes so the optional menu bar matches the frameless
window chrome.
This commit is contained in:
Andreas Kling 2026-05-27 12:32:01 +02:00 committed by Andreas Kling
parent 6c24e536ba
commit 7e034608ef
4 changed files with 57 additions and 0 deletions

View file

@ -225,6 +225,9 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
m_hamburger_menu = new QMenu(this);
menuBar()->setObjectName("LadybirdMenuBar");
update_menu_bar_style();
if (!Settings::the()->show_menubar())
menuBar()->hide();
@ -775,6 +778,11 @@ void BrowserWindow::update_tab_close_button_icons()
}
}
void BrowserWindow::update_menu_bar_style()
{
menuBar()->setStyleSheet(ChromeStyle::menu_bar_style_sheet(palette()));
}
void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlayState play_state)
{
auto* tab = m_tabs_container->tab(index);
@ -1050,6 +1058,7 @@ void BrowserWindow::resizeEvent(QResizeEvent* event)
void BrowserWindow::changeEvent(QEvent* event)
{
if (event->type() == QEvent::PaletteChange) {
update_menu_bar_style();
update_tab_close_button_icons();
} else if (event->type() == QEvent::WindowStateChange) {
QWindowStateChangeEvent* stateChangeEvent = static_cast<QWindowStateChangeEvent*>(event);

View file

@ -165,6 +165,7 @@ private:
void create_close_button_for_tab(Tab*);
void update_tab_close_button_icons();
void update_menu_bar_style();
QIcon icon_for_page_mute_state(Tab&) const;
QString tool_tip_for_page_mute_state(Tab&) const;

View file

@ -289,6 +289,52 @@ QWidget#LadybirdNavigationToolbar QToolButton::menu-indicator {{
background, background_bottom, surface_hover, surface_pressed, control_border, separator, text, disabled_text);
}
QString menu_bar_style_sheet(QPalette const& palette)
{
auto background = style_sheet_color(chrome_tab_strip_background(palette));
auto background_bottom = style_sheet_color(mix(chrome_tab_strip_background(palette), QColor(3, 8, 14), is_dark(palette) ? 0.26 : 0.026));
auto hover = style_sheet_color(chrome_control_surface_hover(palette));
auto pressed = style_sheet_color(chrome_control_surface_pressed(palette));
auto border = style_sheet_color(chrome_border(palette));
auto control_border = style_sheet_color(chrome_control_border(palette));
auto text = style_sheet_color(chrome_button_text(palette));
auto disabled_text = style_sheet_color(chrome_muted_text(palette));
return qformatted(R"(
QMenuBar#LadybirdMenuBar {{
color: {6};
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 {0}, stop:1 {1});
border: 0;
border-bottom: 1px solid {4};
padding: 3px 8px;
spacing: 2px;
}}
QMenuBar#LadybirdMenuBar::item {{
color: {6};
background: transparent;
border: 1px solid transparent;
border-radius: 6px;
padding: 4px 9px;
}}
QMenuBar#LadybirdMenuBar::item:selected {{
background: {2};
border-color: {5};
}}
QMenuBar#LadybirdMenuBar::item:pressed {{
background: {3};
border-color: {5};
}}
QMenuBar#LadybirdMenuBar::item:disabled {{
color: {7};
}}
)",
background, background_bottom, hover, pressed, border, control_border, text, disabled_text);
}
QString location_edit_style_sheet(QPalette const& palette)
{
auto surface_color = chrome_surface(palette);

View file

@ -29,6 +29,7 @@ QColor chrome_muted_text(QPalette const&);
QString style_sheet_color(QColor const&);
QString toolbar_container_style_sheet(QPalette const&);
QString menu_bar_style_sheet(QPalette const&);
QString location_edit_style_sheet(QPalette const&);
QString bookmarks_bar_style_sheet(QPalette const&);
QString find_in_page_style_sheet(QPalette const&);