Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
6da8ba68 by Pierre Lamot at 2025-09-23T08:27:35+00:00
qt: force stylesheet to be re-evaluated when palette changes

As far as I understand, the colors used by the widgets are evaluated when we
set a stylesheet on an item (even if the style sheet doesn't specify any
colors), if the applicationpalette changes afterward, the colors of a widget
with a custom style is not updated properly. Forcing the stylesheet to be
re-evaluated when the palette changes, forces the colors to be updated.

since Qt 5.7, we can use Qt::AA_UseStyleSheetPropagationInWidgetStyles which
propagates the palette automatically

fix: #29315

- - - - -
553e1def by Pierre Lamot at 2025-09-23T08:27:35+00:00
qt: set foreground color when setting background color in stylesheet

otherwise we may end up with not enough contrast between the foreground and the
backgroud color

- - - - -


7 changed files:

- modules/gui/qt/components/interface_widgets.cpp
- modules/gui/qt/components/playlist/selector.cpp
- modules/gui/qt/main_interface.cpp
- modules/gui/qt/qt.cpp
- modules/gui/qt/qt.hpp
- modules/gui/qt/util/customwidgets.cpp
- modules/gui/qt/util/searchlineedit.cpp


Changes:

=====================================
modules/gui/qt/components/interface_widgets.cpp
=====================================
@@ -989,7 +989,19 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf, 
TimeLabel::Display _displayType  )
     CONNECT( THEMIM->getIM(), remainingTimeChanged( bool ),
               this, setRemainingTime( bool ) );
 
-    setStyleSheet( "QLabel { padding-left: 4px; padding-right: 4px; }" );
+
+    auto updateStyle = [this]() {
+        setStyleSheet( "TimeLabel {  padding-left: 4px; padding-right: 4px; }" 
);
+    };
+
+    updateStyle();
+
+//same as Qt::AA_UseStyleSheetPropagationInWidgetStyles
+#if !HAS_QT57
+    connect(qApp, &QApplication::paletteChanged, this, [this, updateStyle](){
+        updateStyle();
+    });
+#endif
 }
 
 void TimeLabel::setRemainingTime( bool remainingTime )


=====================================
modules/gui/qt/components/playlist/selector.cpp
=====================================
@@ -424,7 +424,20 @@ PLSelItem * PLSelector::addItem (
       new QTreeWidgetItem( parentItem ) : new QTreeWidgetItem( this );
 
   PLSelItem *selItem = new PLSelItem( item, qtr( str ) );
-  if ( bold ) selItem->setStyleSheet( "font-weight: bold;" );
+
+
+  if ( bold ) {
+      auto updateStyle = [selItem]() {
+          selItem->setStyleSheet( "font-weight: bold;" );
+      };
+      updateStyle();
+//same as Qt::AA_UseStyleSheetPropagationInWidgetStyles
+#if !HAS_QT57
+      connect(qApp, &QApplication::paletteChanged, selItem, [selItem, 
updateStyle](){
+          updateStyle();
+      });
+#endif
+  }
   setItemWidget( item, 0, selItem );
   item->setData( 0, TYPE_ROLE, (int)type );
   if( !drop ) item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );


=====================================
modules/gui/qt/main_interface.cpp
=====================================
@@ -574,12 +574,22 @@ inline void MainInterface::createStatusBar()
     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
-    timeLabel->setStyleSheet(
-            "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
-    speedLabel->setStyleSheet(
-            "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
-    /* pad both label and its tooltip */
-    nameLabel->setStyleSheet( "padding-left: 5px; padding-right: 5px;" );
+    auto updateStyle = [=]() {
+        timeLabel->setStyleSheet(
+            "QLabel:hover { color: black; background-color: rgba(255, 255, 
255, 50%) }" );
+        speedLabel->setStyleSheet(
+            "QLabel:hover { color: black; background-color: rgba(255, 255, 
255, 50%) }" );
+        /* pad both label and its tooltip */
+        nameLabel->setStyleSheet( "padding-left: 5px; padding-right: 5px;" );
+
+    };
+    updateStyle();
+//same as Qt::AA_UseStyleSheetPropagationInWidgetStyles
+#if !HAS_QT57
+    connect(qApp, &QApplication::paletteChanged, this, [this, updateStyle](){
+        updateStyle();
+    });
+#endif
 
     /* and adding those */
     statusBarr->addWidget( nameLabel, 8 );


=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -584,6 +584,9 @@ static void *ThreadPlatform( void *obj, char *platform_name 
)
     QApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
     QApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
 #endif
+#if HAS_QT57
+    QApplication::setAttribute( Qt::AA_UseStyleSheetPropagationInWidgetStyles, 
true);
+#endif
 
     /* Start the QApplication here */
     QVLCApp app( argc, argv );


=====================================
modules/gui/qt/qt.hpp
=====================================
@@ -48,6 +48,7 @@
 #endif
 
 #define HAS_QT56 ( QT_VERSION >= 0x050600 )
+#define HAS_QT57 ( QT_VERSION >= 0x050700 )
 #define HAS_QT510 ( QT_VERSION >= 0x051000 )
 
 enum {


=====================================
modules/gui/qt/util/customwidgets.cpp
=====================================
@@ -417,7 +417,8 @@ void QToolButtonExt::clickedSlot()
 YesNoCheckBox::YesNoCheckBox( QWidget *parent ) : QCheckBox( parent )
 {
     setEnabled( false );
-    setStyleSheet("\
+    auto updateStyle = [this]() {
+        setStyleSheet("\
                   QCheckBox::indicator:unchecked:hover,\
                   QCheckBox::indicator:unchecked {\
                       image: url(:/toolbar/clear.svg);\
@@ -427,4 +428,12 @@ YesNoCheckBox::YesNoCheckBox( QWidget *parent ) : 
QCheckBox( parent )
                       image: url(:/valid.svg);\
                   }\
         ");
+    };
+    updateStyle();
+//same as Qt::AA_UseStyleSheetPropagationInWidgetStyles
+#if !HAS_QT57
+    connect(qApp, &QApplication::paletteChanged, this, [this, updateStyle](){
+        updateStyle();
+    });
+#endif
 }


=====================================
modules/gui/qt/util/searchlineedit.cpp
=====================================
@@ -37,6 +37,7 @@
 #include <QRect>
 #include <QStyle>
 #include <QStyleOption>
+#include <QApplication>
 
 #include <vlc_intf_strings.h>
 
@@ -51,16 +52,24 @@ SearchLineEdit::SearchLineEdit( QWidget *parent ) : 
QLineEdit( parent )
 
     CONNECT( clearButton, clicked(), this, clear() );
 
-    int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, 
this );
-
-    QFontMetrics metrics( font() );
-    QString styleSheet = QString( "min-height: %1px; "
-                                  "padding-top: 1px; "
-                                  "padding-bottom: 1px; "
-                                  "padding-right: %2px;" )
-                                  .arg( metrics.height() + ( 2 * frameWidth ) )
-                                  .arg( clearButton->sizeHint().width() + 6 );
-    setStyleSheet( styleSheet );
+    auto updateStyle = [=]() {
+        int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 
0, this );
+        QFontMetrics metrics( font() );
+        QString styleSheet = QString( "min-height: %1px; "
+                                     "padding-top: 1px; "
+                                     "padding-bottom: 1px; "
+                                     "padding-right: %2px;" )
+                                 .arg( metrics.height() + ( 2 * frameWidth ) )
+                                 .arg( clearButton->sizeHint().width() + 6 );
+        setStyleSheet( styleSheet );
+    };
+    updateStyle();
+//same as Qt::AA_UseStyleSheetPropagationInWidgetStyles
+#if !HAS_QT57
+    connect(qApp, &QApplication::paletteChanged, this, [this, updateStyle](){
+        updateStyle();
+    });
+#endif
 
     setMessageVisible( true );
 



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/de6771a51b7f5fc67659a2a9fc563c8c62ac59aa...553e1def6a7d8371292208279c1c695206696b00

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/de6771a51b7f5fc67659a2a9fc563c8c62ac59aa...553e1def6a7d8371292208279c1c695206696b00
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to