I am writing an application where I'm trying to apply a custom color to a QPushButton. Example code is shown below:
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
int
main(int argc, char *argv[])
{
QApplication app(argc, argv);
auto* const mainWindow = new QMainWindow;
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);
mainWindow->setCentralWidget(pushButton);
mainWindow->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
)
In the example above, a red color is applied to the button, using a lower alpha value. When compiling the code using Qt5, the following ui is generated:
If the alpha value is adjusted, this is also visible. If the same application is compiled using Qt6, however, it looks like this:
As you can see, the button color is the desired red. However, the rendered alpha value is always the maximum value. If I try to change the alpha value in the code, it does not change the visual outcome.
Am I using the QPalette instance in the wrong way, or has something changed between Qt5 and Qt6 regarding the palette handling? Or is this maybe a bug?
I am using Qt 5.15/6.2 and KDE Plasma 5.27 as desktop environment.

