comparison view/ViewManager.cpp @ 1575:3761d1ea5015 background-mode

More sensible approach to colour setting on Windows
author Chris Cannam
date Mon, 20 Jan 2020 17:18:42 +0000
parents dd7166cdf6bc
children 9c4a057302ff
comparison
equal deleted inserted replaced
1574:dd7166cdf6bc 1575:3761d1ea5015
22 #include "View.h" 22 #include "View.h"
23 #include "Overview.h" 23 #include "Overview.h"
24 24
25 #include <QSettings> 25 #include <QSettings>
26 #include <QApplication> 26 #include <QApplication>
27 #include <QStyleFactory>
27 28
28 #include <iostream> 29 #include <iostream>
29 30
30 //#define DEBUG_VIEW_MANAGER 1 31 //#define DEBUG_VIEW_MANAGER 1
31 32
786 #endif 787 #endif
787 788
788 if (dark) { 789 if (dark) {
789 790
790 #ifdef Q_OS_WIN32 791 #ifdef Q_OS_WIN32
791 // Some UI elements on Windows don't use the palette. 792 // The Windows Vista style doesn't use the palette for many of
792 793 // its controls. They can be styled with stylesheets, but that
793 QString existingStyleSheet = qApp->styleSheet(); 794 // takes a lot of fiddly and fragile custom bits. Easier and
794 if (existingStyleSheet == "") { 795 // more reliable to switch to a non-Vista style which does use
795 QString styleSheet = 796 // the palette.
796 "QFrame { background: #202020; color: #f0f0f0; }\n" 797
797 "QAbstractButton { background: #202020; color: #f0f0f0; }\n" 798 QStyle *plainWindowsStyle = QStyleFactory::create("windows");
798 "QDialog { background-color: #202020; }\n" 799 if (!plainWindowsStyle) {
799 "QToolBar { background-color: #202020; }\n" 800 SVCERR << "Failed to load plain Windows style" << endl;
800 "QMenuBar { background-color: #404040; }\n" 801 } else {
801 "QMenuBar::item:selected { background-color: #707070; }\n" 802 qApp->setStyle(plainWindowsStyle);
802 "QMenuBar::item:pressed { background-color: #707070; }\n"
803 "QComboBox { background-color: #404040; }\n"
804 "QTabWidget::pane { border: 1px solid #c7c7c7; top: -1px; }\n"
805 "QTabBar::tab { background-color: #404040; border: 1px solid #c7c7c7; bottom: -1px; padding: 5px; }\n"
806 "QTabBar::tab:selected { background-color: #707070; }\n"
807 ;
808 qApp->setStyleSheet(styleSheet);
809 } 803 }
810 #endif 804 #endif
811 805
812 QApplication::setPalette(m_darkPalette); 806 QApplication::setPalette(m_darkPalette);
813 807
814 } else { 808 } else {
815 809
816 #ifdef Q_OS_WIN32 810 #ifdef Q_OS_WIN32
817 qApp->setStyleSheet(""); 811 // Switch back to Vista style
812
813 QStyle *fancyWindowsStyle = QStyleFactory::create("windowsvista");
814 if (!fancyWindowsStyle) {
815 SVCERR << "Failed to load fancy Windows style" << endl;
816 } else {
817 qApp->setStyle(fancyWindowsStyle);
818 }
818 #endif 819 #endif
819 820
820 QApplication::setPalette(m_lightPalette); 821 QApplication::setPalette(m_lightPalette);
821 } 822 }
822 } 823 }