Add QDarkStyleSheet to Message Aggregator reference application

This commit is contained in:
Bill Somerville 2018-12-17 01:48:45 +00:00
parent 74112434f9
commit d241217737
3 changed files with 41 additions and 9 deletions

View File

@ -1087,7 +1087,10 @@ qt5_wrap_ui (wsjt_qt_GENUISRCS ${wsjt_qt_UISRCS})
qt5_wrap_ui (wsjtx_GENUISRCS ${wsjtx_UISRCS}) qt5_wrap_ui (wsjtx_GENUISRCS ${wsjtx_UISRCS})
# Resource generation # Resource generation
qt5_add_resources (wsjtx_RESOURCES_RCC ${CMAKE_BINARY_DIR}/wsjtx.qrc) qt5_add_resources (wsjtx_RESOURCES_RCC
${CMAKE_BINARY_DIR}/wsjtx.qrc
contrib/QDarkStyleSheet/qdarkstyle/style.qrc
)
# AX COM servers # AX COM servers
if (WIN32) if (WIN32)
@ -1324,7 +1327,10 @@ target_link_libraries (udp_daemon wsjtx_udp-static)
add_resources (message_aggregator_RESOURCES /qss ${message_aggregator_STYLESHEETS}) add_resources (message_aggregator_RESOURCES /qss ${message_aggregator_STYLESHEETS})
configure_file (UDPExamples/message_aggregator.qrc.in message_aggregator.qrc @ONLY) configure_file (UDPExamples/message_aggregator.qrc.in message_aggregator.qrc @ONLY)
qt5_add_resources (message_aggregator_RESOURCES_RCC ${CMAKE_CURRENT_BINARY_DIR}/message_aggregator.qrc) qt5_add_resources (message_aggregator_RESOURCES_RCC
${CMAKE_CURRENT_BINARY_DIR}/message_aggregator.qrc
contrib/QDarkStyleSheet/qdarkstyle/style.qrc
)
add_executable (message_aggregator add_executable (message_aggregator
${message_aggregator_CXXSRCS} ${message_aggregator_CXXSRCS}
${WSJTX_ICON_FILE} ${WSJTX_ICON_FILE}

View File

@ -63,14 +63,29 @@ int main (int argc, char * argv[])
QObject::connect (&app, SIGNAL (lastWindowClosed ()), &app, SLOT (quit ())); QObject::connect (&app, SIGNAL (lastWindowClosed ()), &app, SLOT (quit ()));
{ {
QFile file {":/qss/default.qss"}; QString ss;
if (!file.open (QFile::ReadOnly)) auto sf = qApp->styleSheet ();
if (sf.size ())
{ {
throw std::runtime_error { sf.remove ("file:///");
QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()} QFile file {sf};
.toLocal8Bit ().constData ()}; if (!file.open (QFile::ReadOnly))
{
throw std::runtime_error {
QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()}.toStdString ()};
}
ss += file.readAll ();
} }
app.setStyleSheet (file.readAll()); {
QFile file {":/qss/default.qss"};
if (!file.open (QFile::ReadOnly))
{
throw std::runtime_error {
QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()}.toStdString ()};
}
ss += file.readAll ();
}
app.setStyleSheet (ss);
} }
MessageAggregatorMainWindow window; MessageAggregatorMainWindow window;

View File

@ -1236,7 +1236,18 @@ void MainWindow::set_application_font (QFont const& font)
qApp->setFont (font); qApp->setFont (font);
// set font in the application style sheet as well in case it has // set font in the application style sheet as well in case it has
// been modified in the style sheet which has priority // been modified in the style sheet which has priority
qApp->setStyleSheet (qApp->styleSheet () + "* {" + font_as_stylesheet (font) + '}'); QString ss;
if (qApp->styleSheet ().size ())
{
auto sheet = qApp->styleSheet ();
sheet.remove ("file:///");
QFile sf {sheet};
if (sf.open (QFile::ReadOnly | QFile::Text))
{
ss = sf.readAll () + ss;
}
}
qApp->setStyleSheet (ss + "* {" + font_as_stylesheet (font) + '}');
for (auto& widget : qApp->topLevelWidgets ()) for (auto& widget : qApp->topLevelWidgets ())
{ {
widget->updateGeometry (); widget->updateGeometry ();