Important: Please read the Qt Code of Conduct -

Setting ampersand(&) as a Text for a push button

  • Hi
    I am working on a virtual keyboard,I want to have ampersand(&) as a text for the pushbutton.
    On click of this button,the ampersand should appear in linedit of keyboard.

    After checking forums,I came across a thread which said & is treated as a accelerator key.
    To set the text of push button, I set it as && so that i can see a single ampersand on the pushbutton.

    Now On Clicking this button ,I see that 2 ampersand is displayed in lineEdit,because iam reading the text of a button to display it in lineedit.

    Any ideas hoe to go about it?
    I tried & doesn't work.

  • Well, the thread you read is correct. To display an & on a button, you have to double it to &&. The solution to your problem is therefore to un-double the && before you display it in a line edit. There are many ways to do this. One would be to simply do a string replace before pasting it on the line edit, where in replace a double && with a single &. Another would be not to use the caption of the button directly, but use another property instead. The latter would be a more flexible solution, I think.

Log in to reply