Results 1 to 2 of 2

Thread: Possible to use an ampersand (&) character in a QCheckBox?

  1. #1
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Possible to use an ampersand (&) character in a QCheckBox?

    Hi,


    Is there any way to include an ampersand (&) character in a QCheckBox text? For example I want to do something like this, but having the "&" to actually show up "as is" in my application:
    Qt Code:
    1. QCheckBox* myCheck = new QCheckBox("Include Comments & Notes");
    To copy to clipboard, switch view to plain text mode 
    With the above code the "&" will just be ignored.

    I've tried to do this in several ways but haven't succeeded. I know that a work-around could be to create an "empty" checkbox and just add a QLabel after, but I'd prefer to just use the QCheckBox, if possible.

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Possible to use an ampersand (&) character in a QCheckBox?

    The ampersand is used as a marker for the QCheckbox shortcut key (described in the docs). In your example you are making the space following the ampersand a shortcut. Try escaping the ampersand with a second one:
    Qt Code:
    1. QCheckBox* myCheck = new QCheckBox("Include Comments && Notes");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. About QCheckBox
    By liushuo0826 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 16th April 2010, 07:14
  2. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 16:28
  3. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 12:25
  4. QCheckbox
    By sonuani in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2008, 14:12
  5. ampersand showing in QLabel
    By dave in forum Newbie
    Replies: 6
    Last Post: 7th November 2006, 07:15

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.