Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Underline(shortcut) is not getting displayed on changing the text on a button
Forum Updated to NodeBB v4.3 + New Features

Underline(shortcut) is not getting displayed on changing the text on a button

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 618 Views 2 Watching
  • 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.
  • M Offline
    M Offline
    MaruthiMarsh
    wrote on last edited by MaruthiMarsh
    #1

    A button is set text with "&Open" where shortcut is "Alt+O" but when I change the text to "Close"/"Cl&ose", the shortcut is getting removed.
    How to retain the shortcut?

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Layouts 1.15
    
    Pane {
    
        function on_update_open_button_text() {
            button.text = "Cl&ose"
        }
    
        Shortcut {
            id: sc
            sequence: "Alt+O"
            onActivated: {
                on_update_open_button_text()
            }
        }
    
        ColumnLayout {
    
            Button {
                id: button
                Layout.preferredWidth: 150
                objectName: "openButtonObj"
                text: "&Open"
    
                onClicked: {
                    on_update_open_button_text()
                }
            }
        }
    }
    
    
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @MaruthiMarsh said in Shortcut gets removed on changing the text on a button:

      the shortcut is getting removed

      What does this mean exactly? What indicates that it is removed?

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MaruthiMarsh
        wrote on last edited by
        #3

        @fcarney I think I need to reframe the title. Basically what is happening is the underline under the character 'O' is not getting displayed when we change the button text to "Cl&ose" though it displays initially (when the text is "&Open").

        J.HilkJ 1 Reply Last reply
        0
        • M MaruthiMarsh

          @fcarney I think I need to reframe the title. Basically what is happening is the underline under the character 'O' is not getting displayed when we change the button text to "Cl&ose" though it displays initially (when the text is "&Open").

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @MaruthiMarsh would button.text = "Cl<u>o</u>se" work for your case ?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            MaruthiMarsh
            wrote on last edited by
            #5

            @J-Hilk Yes, it does work. Thanks.
            But why it doesn't work when '&' is used?

            J.HilkJ 1 Reply Last reply
            0
            • M MaruthiMarsh

              @J-Hilk Yes, it does work. Thanks.
              But why it doesn't work when '&' is used?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @MaruthiMarsh I have no idea what &Ois supposed to do and when I test it, id does nothing but print the & char. <u></u> are rich text tags and the QMLl Text elements supports that, so I suggested to that :D


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0

              • Login

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