Results 1 to 2 of 2

Thread: Disabling the user to change QCheckBox checkstate

  1. #1
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Disabling the user to change QCheckBox checkstate

    Hi

    I'm trying to show a bool value with a QCheckBox, that the user shouldn't be able to change, but without changing the appearance of the QCheckBox.

    This is what I've got so far:

    Qt Code:
    1. checkBox->setEnabled(false);
    2. QPalette palette(checkBox->palette());
    3. palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(Qt::black));
    4. checkBox->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    That changes the text color back to black, but the checked indicator still is grey.
    I tried to change it with a style-sheet:

    Qt Code:
    1. checkBox->setStyleSheet("::indicator { border-color: black; }");
    To copy to clipboard, switch view to plain text mode 
    ...with that the indicator isn't visible.

    Qt Code:
    1. checkBox->setStyleSheet("::indicator { width: 12px; height: 12px; border-width: 1px; border-style: solid; border-color: black; }");
    To copy to clipboard, switch view to plain text mode 
    ... with that it is, but it just looks weird, plus the check doesn't show.

    There has to be a simpler way.
    I already thought about just connecting the QCheckBox toggled(bool checked) signal to a slot connected to:

    Qt Code:
    1. void::myClass checkBoxToggled(bool checked)
    2. {
    3. checkbox->setChecked(whatever I need);
    4. }
    To copy to clipboard, switch view to plain text mode 

    ..or something like that.

    Any suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Disabling the user to change QCheckBox checkstate

    I would go for connecting the toggled() signal to a slot and resetting the value if I wanted to do it the way you want. But from user friendliness point of view, you should just disable the checkbox and accept that it changes appearance - the user should be aware that he can't change the state of the box.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to change defualt color of QCheckbox box?
    By darshan.hardas in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2008, 13:24
  2. Replies: 1
    Last Post: 22nd June 2007, 19:46

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.