Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Weird behavior when switching the view between Image and Camera
Forum Updated to NodeBB v4.3 + New Features

Weird behavior when switching the view between Image and Camera

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 923 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    Trying to switch the view between camera and image, but the results are pretty weird

    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}
        }
    ]
    

    }
    @

    Once the state is "CAMERA" and I click on the "fullScreen" button
    The photoTest.qml do not show me the fullsize of the camera but
    the fullsize of the photo, what is happening?What kind of error do I make?

    Qt version : 5.1Beta
    os : mac osx 10.8.3
    compiler: clang 3.2

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stereomatching
      wrote on last edited by
      #2

      I explicit specified the state of "FULLSCREEN" in main.qml as

      @
      State {
      name: "FULLSCREEN"

              PropertyChanges { target: photoTest; state: param.fullScreenPreviousState == "PHOTO" ? "PHOTO" : "CAMERA"} //new conditon
              PropertyChanges { target: toolBarTest; width: 0}
          }
      

      @

      We have to explicit specify all of the conditions of different components when changing state?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved