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. [Solved] Problem with customized ButtonStyle - Text shows &

[Solved] Problem with customized ButtonStyle - Text shows &

Scheduled Pinned Locked Moved QML and Qt Quick
qmlbuttonstyles
2 Posts 1 Posters 2.1k 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.
  • H Offline
    H Offline
    hpollak
    wrote on last edited by hpollak
    #1

    Hy!!

    I try to customize my Buttons. In all my qml Files i use:

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Controls.Styles 1.3
    
       Button {
            id: prjNew
            x: 4 * projectRec.tabWidth
            anchors.top: projectState.bottom
            anchors.topMargin: 5
            iconSource: "qrc:/icons/resources/document-new-3.png"
    
            style: MyButtonStyle {}
    
            action: newPrjAction
        }
    

    The Action is difined as:

       Action {
            id: newPrjAction
    
            text: "&New Project..."
            shortcut: "Ctrl+N"
            tooltip: "Press to create an new Project"
            onTriggered: {
                console.info("New Project pressed...");
    
                filterTab.enabled=false;
                alarmTab.enabled = false;
                addDescTab.enabled = false;
                prjClose.enabled = false;
    
            }
        }
    

    The code from my Style:

    ButtonStyle {
        
        id: myButtonStyle
    
        background: Rectangle {
            implicitWidth: 100
            implicitHeight: 25
            border.width: control.activeFocus ? 2 : 1
            border.color: "#888"
            radius: 4
    
    
            gradient: Gradient {
                            GradientStop { position: 0 ; color: control.pressed ? appPalette.button_clicked_gradient_start :  appPalette.button_gradient_start }
                            GradientStop { position: 1 ; color: control.pressed ? appPalette.button_clicked_gradient_stop :  appPalette.button_gradient_stop }
            }
        }
    
        label: Component{
            id:labelCompoent
            Row{
                anchors.left: parent.left
                anchors.leftMargin: (parent.width - (text.width + image.width))/2
                anchors.top: parent.top
                anchors.topMargin: 2
                spacing: 0
                Image{ id:image ;source: control.iconSource}
                Label{
                    id: text
                    height: image.height
                    width:100
                    horizontalAlignment:Text.AlignHCenter
                    verticalAlignment:  Text.AlignVCenter
    
                    color: control.enabled ? appPalette.text_color : appPalette.text_color_disabled
    
                    text: control.text
                }
            }
        }
    
    }
    

    Now The Problem:

    The Button looks nice, but instead of <u>N</u>ew Project... the Button Text is shown as "&New Project...".
    Using the Button without MyStyle the Text is shown correctly.

    Does anyone have an Idea, what I'm doing wrong?

    Best regards!

    Harry

    PS: Shortcuts, ToolTips,... working without any problems

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hpollak
      wrote on last edited by
      #2

      I have found a solution myself in the QT-Sourcecode of ButtonStyle.qml. I have to :

      import QtQuick.Controls.Private 1.0
      

      in myButtonStyle.qml and in the LabelSection I use The StyleHelpers.stylizeMnemonics, so my ButtonStyle.qml looks like:

      import QtQuick 2.4
      import QtQuick.Controls 1.3
      import QtQuick.Controls.Styles 1.3
      import QtQuick.Controls.Private 1.0
      
      ButtonStyle {
          
          id: myButtonStyle
      
          background: Rectangle {
              implicitWidth: 100
              implicitHeight: 25
              border.width: control.activeFocus ? 2 : 1
              border.color: "#888"
              radius: 4
      
      
              gradient: Gradient {
                              GradientStop { position: 0 ; color: control.pressed ? appPalette.button_clicked_gradient_start :  appPalette.button_gradient_start }
                              GradientStop { position: 1 ; color: control.pressed ? appPalette.button_clicked_gradient_stop :  appPalette.button_gradient_stop }
              }
          }
      
          label: Component{
              id:labelCompoent
              Row{
                  anchors.left: parent.left
                  anchors.leftMargin: (parent.width - (text.width + image.width))/2
                  anchors.top: parent.top
                  anchors.topMargin: 2
                  spacing: 0
                  Image{ id:image ;source: control.iconSource}
                  Label{
                      id: text
                      height: image.height
                      width:100
                      horizontalAlignment:Text.AlignHCenter
                      verticalAlignment:  Text.AlignVCenter
      
                      color: control.enabled ? appPalette.text_color : appPalette.text_color_disabled
      
                      text: StyleHelpers.stylizeMnemonics(control.text)
                  }
              }
          }
      
      }
      
      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