Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jul 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

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

    Hello. I want to make different icons for checked and unchecked state of QPushButton. The code:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. QBoxLayout *layout1 = new QVBoxLayout();
    5.  
    6. QWidget *widget = new QWidget(this);
    7. widget->setLayout(layout1);
    8. setCentralWidget(widget);
    9.  
    10. QIcon icon1;
    11. icon1.addFile(QStringLiteral(":/norecord.png"), QSize(), QIcon::Normal, QIcon::Off);
    12. icon1.addFile(QStringLiteral(":/active.png"), QSize(), QIcon::Normal, QIcon::On);
    13.  
    14. QPushButton *button1 = new QPushButton(this);
    15. button1->setCheckable(true);
    16. button1->setText("Sample Text");
    17. button1->setIcon(icon1);
    18. layout1->addWidget(button1);
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. case CE_PushButtonLabel:
    2. if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
    3. QStyleOptionButton b(*button);
    4. // no PM_ButtonShiftHorizontal and PM_ButtonShiftVertical for fusion style
    5. b.state &= ~(State_On | State_Sunken);
    6. QCommonStyle::drawControl(element, &b, painter, widget);
    7. }
    8. break;
    To copy to clipboard, switch view to plain text mode 
    I want to ask: Is it a correct code? Is it a bug or style feature?

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    552
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    I would guess you're using the fusion style?
    https://codereview.qt-project.org/c/qt/qtbase/+/327734

  3. #3
    Join Date
    Jul 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

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

    Quote Originally Posted by ChristianEhrlicher View Post
    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...

Similar Threads

  1. Replies: 0
    Last Post: 11th July 2016, 14:02
  2. Replies: 2
    Last Post: 18th November 2015, 13:57
  3. Replies: 4
    Last Post: 11th October 2013, 10:23
  4. What is a checkable QPushButton?
    By szisziszilvi in forum Newbie
    Replies: 1
    Last Post: 4th August 2011, 13:54
  5. Coloring checkable QPushbutton with style sheet
    By RThaden in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2008, 18:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.