Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCheckBox not displaying checked state
QtWS25 Last Chance

QCheckBox not displaying checked state

Scheduled Pinned Locked Moved Solved General and Desktop
qt 5.7qcheckboxsignals&slotsgui
4 Posts 2 Posters 5.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CybeX
    wrote on 23 Jan 2017, 00:56 last edited by SGaist
    #1

    Hi all

    I have been developing a GUI, and have run into an issue (or possible bug) with a QCheckBox.

    Problem

    Adding a QCheckBox component to my form, compiling and running it has no issues. However, when clicking on the checkbox, no visible feedback is displayed.

    I added a listener for the clicked(bool) signal It is used in the debug output to display the current state, which does change.

    More Information

    Only 3 settings are changed on the checkbox:

    1. Component Text
    2. Component Name
    3. Component Checkedstate : Checked.

    I added another checkbox to the page, recompiled and ran it without changing anything. Again, this new checkbox does not respond to changes.

    Furthermore, I created a new project, added only a checkbox, compiled and ran it. Had no issues displaying the state change. Must be an issue with my project.

    Output of stateChanged(int) and clicked(bool) signals: (qDebug() output)

    QCHECKBOX STATE (stateChanged):  "2"
    QCHECKBOX STATE (clicked):  "checked"
    QCHECKBOX STATE (stateChanged):  "0"
    QCHECKBOX STATE (clicked):  "unchecked"
    QCHECKBOX STATE (stateChanged):  "2"
    QCHECKBOX STATE (clicked):  "checked"
    QCHECKBOX STATE (stateChanged):  "0"
    QCHECKBOX STATE (clicked):  "unchecked"
    

    If any additional project info is required, feel free to leave a comment

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 23 Jan 2017, 08:19 last edited by
      #2

      Weird case. Are you using QSS by any chance? Perhaps you ran into https://bugreports.qt.io/browse/QTBUG-48023

      (Z(:^

      C 1 Reply Last reply 23 Jan 2017, 08:29
      1
      • S sierdzio
        23 Jan 2017, 08:19

        Weird case. Are you using QSS by any chance? Perhaps you ran into https://bugreports.qt.io/browse/QTBUG-48023

        C Offline
        C Offline
        CybeX
        wrote on 23 Jan 2017, 08:29 last edited by
        #3

        @sierdzio you are correct, after much searching, I found out that in the CSS, setting the QCheckBox::indicator color will mess with the checkbox mark.

        I will post a solution shortly

        Thanks for asking though!

        1 Reply Last reply
        2
        • C Offline
          C Offline
          CybeX
          wrote on 23 Jan 2017, 08:38 last edited by CybeX
          #4

          Here is a possible solution for solving this "missing check/mark" issue.

          I implemented the CSS "indicator" solution I got from this qt form post which is problematic.

          Sources of solution:

          • Doc page: here
          • Implementation: here
          QPalette p = ui->checkBox->palette();
          p.setColor(QPalette::Active, QPalette::Base, QColor(255, 255, 255));
          p.setColor(QPalette::Button, QColor(255, 255, 255));
          ui->checkBox->setAutoFillBackground(true);
          ui->checkBox->setPalette(p);
          
          QColor(255, 255, 255)
          

          refers to your desired background color, possibly the same color as your window background, etc.

          QPallete::Active,  QPalette::base
          

          refers to the active checkbox's background (the white box background)

          QPalette::Button
          

          refers to the "actual background" (behind the checkbox and the checkbox text)

          Hope this helps!

          1 Reply Last reply
          1

          1/4

          23 Jan 2017, 00:56

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved