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

Checkable QPushbutton ignores or overrules stylesheet checked:background

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.7.0
    • 4.6.0
    • Widgets: Style Sheets
    • None
    • Windows XP, Qt 4.6 build with Visual Studio 2008
    • 9b0502aa6abf6bb9c07f205bccdf2d9c65027bde

    Description

      When a QPushButton is set to checkable and the checked attribute is used to define a background, this will not work.

      If the following piece of code is executed and the button is checked then the text color will become blue, but the background will change back to grey

      // Create a new button
      QPushButton* button = new QPushButton("Button", this);
      // Move and resize the button
      button->setGeometry(50, 10, 100, 30);
      // Set button checkable
      button->setCheckable(true);
      // Set the style sheet
      // Here is the problem, when checked background should be red, but becomes grey again
      // The color is blue in checked state as it should be
      button->setStyleSheet(
      ":checked

      { background : red; color: blue }

      "
      ":pressed

      { background : red; color: blue }

      "
      );
      // Show the button
      button->show();

      How can this be resolved?

      Attachments

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

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            lucwollants Luc Wollants
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes