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

Different icons for checkable QPushButton is not works on Linux and Android

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.15.2
    • Widgets: Styles
    • None
    • Android, Linux/X11

    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.

      Attachments

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

        Activity

          People

            tpochep Timur Pocheptsov
            sergm Sergey Mudry
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes