Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
5.15.2
-
None
Description
I want to make different icons for checked and unchecked state of QPushButton. Sample 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;
This code always clear the State_On flag. But I do not know why it was done.