DarkStyle.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. ###############################################################################
  3. # #
  4. # The MIT License #
  5. # #
  6. # Copyright (C) 2017 by Juergen Skrotzky (JorgenVikingGod@gmail.com) #
  7. # >> https://github.com/Jorgen-VikingGod #
  8. # #
  9. # Sources: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle #
  10. # #
  11. ###############################################################################
  12. */
  13. #include "DarkStyle.h"
  14. DarkStyle::DarkStyle() : DarkStyle(styleBase()) {}
  15. DarkStyle::DarkStyle(QStyle *style) : QProxyStyle(style) {}
  16. QStyle *DarkStyle::styleBase(QStyle *style) const {
  17. static QStyle *base =
  18. !style ? QStyleFactory::create(QStringLiteral("Fusion")) : style;
  19. return base;
  20. }
  21. QStyle *DarkStyle::baseStyle() const { return styleBase(); }
  22. void DarkStyle::polish(QPalette &palette) {
  23. // modify palette to dark
  24. palette.setColor(QPalette::Window, QColor(53, 53, 53));
  25. palette.setColor(QPalette::WindowText, Qt::white);
  26. palette.setColor(QPalette::Disabled, QPalette::WindowText,
  27. QColor(127, 127, 127));
  28. palette.setColor(QPalette::Base, QColor(42, 42, 42));
  29. palette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
  30. palette.setColor(QPalette::ToolTipBase, Qt::white);
  31. palette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
  32. palette.setColor(QPalette::Text, Qt::white);
  33. palette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
  34. palette.setColor(QPalette::Dark, QColor(35, 35, 35));
  35. palette.setColor(QPalette::Shadow, QColor(20, 20, 20));
  36. palette.setColor(QPalette::Button, QColor(53, 53, 53));
  37. palette.setColor(QPalette::ButtonText, Qt::white);
  38. palette.setColor(QPalette::Disabled, QPalette::ButtonText,
  39. QColor(127, 127, 127));
  40. palette.setColor(QPalette::BrightText, Qt::red);
  41. palette.setColor(QPalette::Link, QColor(42, 130, 218));
  42. palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
  43. palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
  44. palette.setColor(QPalette::HighlightedText, Qt::white);
  45. palette.setColor(QPalette::Disabled, QPalette::HighlightedText,
  46. QColor(127, 127, 127));
  47. }
  48. void DarkStyle::polish(QApplication *app) {
  49. if (!app) return;
  50. // loadstylesheet
  51. QFile qfDarkstyle(QStringLiteral(":/darkstyle/darkstyle.qss"));
  52. if (qfDarkstyle.open(QIODevice::ReadOnly | QIODevice::Text)) {
  53. // set stylesheet
  54. QString qsStylesheet = QString::fromLatin1(qfDarkstyle.readAll());
  55. app->setStyleSheet(qsStylesheet);
  56. qfDarkstyle.close();
  57. }
  58. }