PDA

View Full Version : How to change Gradient color of button with Enter Key Pressed Event ? :(:(



duc_bkav
11th November 2011, 08:42
Hi everyone,

I have a problem that when i try to design my GUI,
i use one Button.qml file to design my Button. And this button use Gradient to describe default color.

But when i try to use Keyboard event, i cannot to use Enter keyboard event to trigger this default color.

the console pop up a message like this : Cannot assign null to QColor

Can somebody help me debug this error ?

Thank u so much

duc_bkav
12th November 2011, 03:12
import QtQuick 1.0

Rectangle {
id: container

property variant text
signal clicked

height: text.height + 25; width: text.width + 20;
border.width: 7
radius: 100
smooth: true

gradient: Gradient {
GradientStop {
position: 0.0
color: !mouseArea.pressed ? activePalette.light : activePalette.button //this
}
GradientStop {
position: 1.0
color: !mouseArea.pressed ? activePalette.button : activePalette.dark //this
}
}



SystemPalette { id: activePalette }
Text {
id: text
x: 0
y: 0
text: container.text
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
wrapMode: Text.WordWrap
opacity: 1
smooth: true
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
style: Text.Outline
font.bold: true
font.pointSize: 35
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: container.clicked()
}
}



Now, i want to use Keys.onEnterPressed event to trigger the button instead of use mouse clicked event.

But when i attemp to replace mouseArea.pressed with Keys.onEnterPressed , start debugging program, in mainwindow.qml form, when i focus on particular button and i press Enter, the button doesn't seem to be trigger . It has no thing to be pop up in console.log() window .

Anybody can help me, i'm very faithful for you help :(

duc_bkav
13th November 2011, 02:30
Is there anybody can help me or show me a way to use EnterPressed Event to trigger Button instead of Mouse Clicked Event , please point this out for me :(