尝试在相机和图像之间切换视图,但结果非常奇怪
ToolBarTest.qml
import QtQuick 2.0
Item{
id:root
height: 800; width: 144
signal fullScreen()
signal camera()
signal photo()
Column{
id: toolBarColumn
anchors.fill: root
spacing: 10
Rectangle{
width: 144
height: 70
color: "blue"
Text{
text: "fullScreen"
}
MouseArea{
anchors.fill: parent
onClicked: {
fullScreen()
}
}
}
Rectangle{
width: 144
height: 70
color: "blue"
Text{
text: "camera"
}
MouseArea{
anchors.fill: parent
onClicked: {
camera()
}
}
}
Rectangle{
width: 144
height: 70
color: "blue"
Text{
text: "photo"
}
MouseArea{
anchors.fill: parent
onClicked: {
photo()
}
}
}
}
}
PhotoTest.qml
import QtQuick 2.0
import QtMultimedia 5.0
Rectangle{
id: root
width: 480
height: 320
color: "black"
state: "PHOTO"
property alias source: largeImage.source
property var theID: largeImage
QtObject{
id: param
property var theID: largeImage
}
Image{
id : largeImage
anchors.fill: parent
cache: false
fillMode: Image.PreserveAspectFit
smooth: true
}
Camera{
id: camera
}
VideoOutput {
id: videoOutput
anchors.fill: parent
source: camera
}
states:[
State {
name: "PHOTO"
StateChangeScript{
script:{
camera.stop()
param.theID = largeImage
}
}
PropertyChanges { target: largeImage; opacity: 1}
PropertyChanges { target: videoOutput; opacity: 0}
},
State {
name: "CAMERA"
StateChangeScript{
script:{
camera.captureMode = Camera.CaptureStillImage
camera.start()
param.theID = videoOutput
}
}
PropertyChanges {target: largeImage; opacity: 0}
PropertyChanges { target: videoOutput; opacity: 1}
}
]
}
main.qml
import QtQuick 2.0
Rectangle {
id: root
width: 800
height: 480
QtObject{
id: param
property string previousFullScreenState
}
ToolBarTest{
id: toolBarTest
onFullScreen: {
param.previousFullScreenState = root.state
root.state = "FULLSCREEN"
}
onPhoto: {
root.state = "PHOTO"
}
onCamera: {
root.state = "CAMERA"
}
}
PhotoTest{
id: photoTest
anchors.left: toolBarTest.right
width: parent.width - toolBarTest.width
source: "/Users/yyyy/Downloads/1359170070532.jpg"
MouseArea{
anchors.fill: parent
onClicked: {
if(root.state == "FULLSCREEN"){
root.state = param.previousFullScreenState
}
}
}
}
states: [
State {
name: "PHOTO"
PropertyChanges { target: photoTest; state: "PHOTO"}
PropertyChanges { target: toolBarTest; width: 144}
},
State {
name: "CAMERA"
PropertyChanges { target: photoTest; state: "CAMERA"}
PropertyChanges { target: toolBarTest; width: 144}
},
State {
name: "FULLSCREEN"
PropertyChanges { target: toolBarTest; width: 0}
}
]
}
状态为“CAMERA”后,我点击“fullScreen”按钮 photoTest.qml没有显示相机的全尺寸,但是 照片的全尺寸,发生了什么?我做了什么样的错误?
Qt版本:5.1Beta os:mac osx 10.8.3 编译器:clang 3.2
答案 0 :(得分:0)
我明确地将main.qml中的“FULLSCREEN”状态指定为
State {
name: "FULLSCREEN"
PropertyChanges { target: photoTest; state: param.fullScreenPreviousState == "PHOTO" ? "PHOTO" : "CAMERA"} //new conditon
PropertyChanges { target: toolBarTest; width: 0}
}
在更改状态时,我们必须明确指定不同组件的所有条件吗?