Qt 使QML文本字段闪烁
单击按钮时,我希望Qt 使QML文本字段闪烁,qt,qml,Qt,Qml,单击按钮时,我希望TextField闪烁。使用QTimer很容易: void MyLineEdit::buttonClickedSlot{ for(int i=1;i<15;i+=2){ QTimer::singleShot(100*i, this, SLOT(changeBackgroundColor("QLineEdit{background: red;}"))); QTimer::singleShot(100*(i+1), this, SLOT((changeBack
TextField
闪烁。使用QTimer很容易:
void MyLineEdit::buttonClickedSlot{
for(int i=1;i<15;i+=2){
QTimer::singleShot(100*i, this, SLOT(changeBackgroundColor("QLineEdit{background: red;}")));
QTimer::singleShot(100*(i+1), this, SLOT((changeBackgroundColor("QLineEdit{background: white;}")));
}
}
void MyLineEdit::changeBackgroundColor(QString str){
this->setStyleSheet(str)
}
这里的问题是存在编译错误:未定义rect。我应该如何解决这个问题?试试这个:
Column{
anchors.fill: parent
TextField{
id: txt
text: "hello"
property string color: "white"
style: TextFieldStyle{
background: Rectangle {
id: rect
radius: 2
implicitWidth: 100
implicitHeight: 24
border.color: "#333"
border.width: 1
color: txt.color
Behavior on color {
SequentialAnimation {
loops: 3
ColorAnimation { from: "white"; to: "red"; duration: 300 }
ColorAnimation { from: "red"; to: "white"; duration: 300 }
}
}
}
}
}
Button{
text: "blink"
onClicked: {
txt.color = "red";
txt.color = "white";
}
}
}
试试这个:
Column{
anchors.fill: parent
TextField{
id: txt
text: "hello"
property string color: "white"
style: TextFieldStyle{
background: Rectangle {
id: rect
radius: 2
implicitWidth: 100
implicitHeight: 24
border.color: "#333"
border.width: 1
color: txt.color
Behavior on color {
SequentialAnimation {
loops: 3
ColorAnimation { from: "white"; to: "red"; duration: 300 }
ColorAnimation { from: "red"; to: "white"; duration: 300 }
}
}
}
}
}
Button{
text: "blink"
onClicked: {
txt.color = "red";
txt.color = "white";
}
}
}
试试这个:
Column{
anchors.fill: parent
TextField{
id: txt
text: "hello"
property string color: "white"
style: TextFieldStyle{
background: Rectangle {
id: rect
radius: 2
implicitWidth: 100
implicitHeight: 24
border.color: "#333"
border.width: 1
color: txt.color
Behavior on color {
SequentialAnimation {
loops: 3
ColorAnimation { from: "white"; to: "red"; duration: 300 }
ColorAnimation { from: "red"; to: "white"; duration: 300 }
}
}
}
}
}
Button{
text: "blink"
onClicked: {
txt.color = "red";
txt.color = "white";
}
}
}
试试这个:
Column{
anchors.fill: parent
TextField{
id: txt
text: "hello"
property string color: "white"
style: TextFieldStyle{
background: Rectangle {
id: rect
radius: 2
implicitWidth: 100
implicitHeight: 24
border.color: "#333"
border.width: 1
color: txt.color
Behavior on color {
SequentialAnimation {
loops: 3
ColorAnimation { from: "white"; to: "red"; duration: 300 }
ColorAnimation { from: "red"; to: "white"; duration: 300 }
}
}
}
}
}
Button{
text: "blink"
onClicked: {
txt.color = "red";
txt.color = "white";
}
}
}