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