Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Setting ampersand(&) as a Text for a push button
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 12.0k 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.
  • L Offline
    L Offline
    lepepper
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1

      • Login

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