Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122781

QPushButton always rendered with same color regardless of used alpha value with fusion style

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.3, 6.2.4, 6.4.2
    • Widgets: Styles
    • None
    • Used OS: Ubuntu 22.04 LTS, Ubuntu 23.10
    • All

    Description

      Consider the following code:

      #include <QApplication>
      #include <QPushButton>
      
      int
      main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          auto* const pushButton = new QPushButton("Click me!");
      
          auto palette = QPalette();
          palette.setColor(QPalette::Button, QColor(255, 0, 0, 50));
      
          pushButton->setAutoFillBackground(true);
          pushButton->setPalette(palette);
          pushButton->show();
      
          return app.exec();
      }
      

      CMakeLists.txt:

      cmake_minimum_required(VERSION 3.8)
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      project(ExampleProject LANGUAGES CXX)
      
      find_package(QT NAMES Qt5 COMPONENTS Widgets REQUIRED)
      find_package(Qt5 COMPONENTS Widgets REQUIRED)
      
      add_executable(ExampleProject
          ${CMAKE_CURRENT_LIST_DIR}/main.cpp
      )
      
      target_link_libraries(ExampleProject
          PRIVATE Qt::Widgets
      )

      This generates a QPushButton instance with a red color and lower alpha value. When compiling with Qt5, this generates the following widget:

      The lower alpha value and red color are clearly visible. If the alpha value is adjusted, the rendered color also changes.
      However, if the code is compiled using Qt6, the following widget is generated:

      Regardless of the entered alpha value, the rendered button color always stays the same.
      Note: Using the setFlat option or applying a windows style temporarily fixed the alpha value problem:

      // Apply either one of these to fix the alpha value problem above
      pushButton->setFlat(true);
      pushButton->setStyle(QStyleFactory::create("Windows"));

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            bakefish Back Fisch
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes