PDA

View Full Version : Different icons for checkable QPushButton is not works on Linux and Android



Sergm
16th July 2021, 09:13
Hello. I want to make different icons for checked and unchecked state of QPushButton. The code:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QBoxLayout *layout1 = new QVBoxLayout();

QWidget *widget = new QWidget(this);
widget->setLayout(layout1);
setCentralWidget(widget);

QIcon icon1;
icon1.addFile(QStringLiteral(":/norecord.png"), QSize(), QIcon::Normal, QIcon::Off);
icon1.addFile(QStringLiteral(":/active.png"), QSize(), QIcon::Normal, QIcon::On);

QPushButton *button1 = new QPushButton(this);
button1->setCheckable(true);
button1->setText("Sample Text");
button1->setIcon(icon1);
layout1->addWidget(button1);

}

I use Qt 5.15.2. This code works in Windows, but not in Linux and Android, there always shows an icon for a unchecked state.
On Qt 5.11.3 and earlier versions it worked.

As far as I could understand, the problem causes this code in the Fusion style, file src/widgets/styles/qfusionstyle.cpp:


case CE_PushButtonLabel:
if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
QStyleOptionButton b(*button);
// no PM_ButtonShiftHorizontal and PM_ButtonShiftVertical for fusion style
b.state &= ~(State_On | State_Sunken);
QCommonStyle::drawControl(element, &b, painter, widget);
}
break;

I want to ask: Is it a correct code? Is it a bug or style feature?

ChristianEhrlicher
18th July 2021, 17:48
I would guess you're using the fusion style?
https://codereview.qt-project.org/c/qt/qtbase/+/327734

Sergm
18th July 2021, 18:12
I would guess you're using the fusion style?
https://codereview.qt-project.org/c/qt/qtbase/+/327734
Yes, Fusion. Thanks. Fixed at 6.1...