我有我的新PyQt5应用程序。我想在QMainWindow中添加QQuickWidget,并用QML设置他的属性。这是我做的:只有当点击PyQt5时,矩形状态才会改变QML
class mainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(mainWindow,self).__init__()
self.setGeometry(100,100,800,600)
engine = PyQt5.QtQml.QQmlEngine(self)
view = QtQuickWidgets.QQuickWidget(engine,self)
view.setSource(PyQt5.QtCore.QUrl("files/newqml.qml"))
到QML文件创建与各国矩形应该当鼠标悬停按钮进行更改。但是当它被徘徊时 - 什么都没有发生。当我点击按钮并点击并离开按钮时,状态发生变化。请帮帮我。我怎样才能做到这一点?
全部QML代码:
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.2
Rectangle{
signal buttonPressedSignal
signal buttonReleasedSignal
id: topButton
width:80
height: 40
color: 'white'
border {width: 2; color: '#4CAF50'}
state: 'Normal'
Text {
id: buttonText
anchors.centerIn: parent
text:'Button'
font.pixelSize: 20
font.family: 'Hallo sans'
color: 'black'
}
MouseArea{
anchors.fill: topButton
hoverEnabled: true
onPressed: parent.buttonPressedSignal()
onReleased: parent.buttonReleasedSignal()
onEntered: parent.state='NotNormal'
onExited: parent.state = 'Normal'
}
states:[
State{
name: 'Normal';
PropertyChanges{target:buttonText;color:'black';easing.type:Easing.InOutElastic}
},
State{
name:'NotNormal';
PropertyChanges{target:buttonText;color:'white';easing.type:Easing.InOutElastic}
}
]
transitions:[
Transition{
to: '*'
ColorAnimation{target:buttonText;duration:400}
}
]
}
你可以放置QML代码 – eyllanesc
我添加的代码 – Polly