在Qt Creator中,我有一个带有"更多"的QML窗口。按钮在底部。如果单击按钮,窗口会根据状态扩大或缩小。
这适用于Kubuntu,但在Windows 10中,按钮位于中间位置,只有下方按钮才能进行下一次点击。
Sceenshoots:
Kubuntu 15.10
~$ qmake --version
QMake version 3.0
Using Qt version 5.4.2 in /usr/lib/x86_64-linux-gnu
Windows 10
C:\Qt\Qt5.5.1\5.5\mingw492_32\bin>qmake.exe --version
QMake version 3.0
Using Qt version 5.5.1 in C:/Qt/Qt5.5.1/5.5/mingw492_32/lib
最小工作示例:
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
id: main
visible: true
width: 200
height: 100
maximumHeight: 200
maximumWidth: 200
Rectangle {
id: rectangleMoreButton
height: 40
width: parent.width
color: "#4a4a4a"
border.color: "#ffffff"
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
Text {
id: textMoreButton
text: "more"
color: "#ffffff"
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
rectangleMoreButton.state == 'more' ? rectangleMoreButton.state = "" : rectangleMoreButton.state = 'more'
}
}
states: [
State {
name: "more"
onCompleted: {
textMoreButton.text = "less"
main.height = 200
}
},
State {
name: ""
onCompleted: {
textMoreButton.text = "more"
main.height = 100
}
}
]
}
}
问题:
我怎样才能更新"更多" /"更少"在QML中改变主窗口高度后的矩形按钮来解决这个问题?如果高度发生变化,是否有办法强制更新或重新绘制窗口?
编辑解决方法:
我找到了一个解决方法来修复Windows中的挂起按钮:添加一个计时器,在调整窗口大小后,它只运行一次,毫秒时间偏移:
Timer {
id: timerUpdateMoreButton
interval: 1
onTriggered: {
rectangleMoreButton.y = main.y
timerUpdateMoreButton.running = false
}
}
和#34;更多"状态,计时器必须激活:
timerUpdateMoreButton.running = true