Add dark theme button

This commit is contained in:
wheremyfoodat 2023-09-30 17:51:48 +03:00
parent 155d2b8f24
commit 837bf7524f
2 changed files with 43 additions and 1 deletions

View file

@ -1,6 +1,9 @@
#pragma once
#include <QApplication>
#include <QMenuBar>
#include <QPalette>
#include <QPushBUtton>
#include <QtWidgets>
#include "panda_qt/screen.hpp"
@ -9,8 +12,13 @@ class MainWindow : public QMainWindow {
Q_OBJECT
private:
QMenuBar* menuBar = nullptr;
QPushButton* themeButton = nullptr;
ScreenWidget screen;
void setDarkTheme();
public:
MainWindow(QApplication* app, QWidget* parent = nullptr);
~MainWindow();
};

View file

@ -4,7 +4,41 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
setWindowTitle("Alber");
// Enable drop events for loading ROMs
setAcceptDrops(true);
resize(320, 240);
screen.show();
// Set our menu bar up
menuBar = new QMenuBar(this);
setMenuBar(menuBar);
auto pandaMenu = menuBar->addMenu(tr("PANDA"));
auto pandaAction = pandaMenu->addAction(tr("panda..."));
auto themeButton = new QPushButton(tr("Dark theme"), this);
themeButton->setGeometry(40, 40, 100, 400);
themeButton->show();
connect(themeButton, &QPushButton::pressed, this, [&]() { setDarkTheme(); });
}
MainWindow::~MainWindow() { delete menuBar; }
void MainWindow::setDarkTheme() {
QApplication::setStyle(QStyleFactory::create("Fusion"));
QPalette p;
p.setColor(QPalette::Window, QColor(53, 53, 53));
p.setColor(QPalette::WindowText, Qt::white);
p.setColor(QPalette::Base, QColor(25, 25, 25));
p.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
p.setColor(QPalette::ToolTipBase, Qt::white);
p.setColor(QPalette::ToolTipText, Qt::white);
p.setColor(QPalette::Text, Qt::white);
p.setColor(QPalette::Button, QColor(53, 53, 53));
p.setColor(QPalette::ButtonText, Qt::white);
p.setColor(QPalette::BrightText, Qt::red);
p.setColor(QPalette::Link, QColor(42, 130, 218));
p.setColor(QPalette::Highlight, QColor(42, 130, 218));
p.setColor(QPalette::HighlightedText, Qt::black);
qApp->setPalette(p);
}