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. Pinch Area with a VisualDataModel[SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Pinch Area with a VisualDataModel[SOLVED]

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.2k 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.
  • G Offline
    G Offline
    godbod
    wrote on last edited by
    #1

    Hello everyone,

    I have a problem having a PinchArea within a visualDataModel. How can I manage to solve this problem please.

    here is the code :

    @
    // pinch.qml

    import QtQuick 1.1
    import "ImageLoader.js" as ImageLoader

    Rectangle
    {
    //width: view.width
    //height: view.height
    height: 720
    width: 1001
    color: "black"
    //color: pinchy.pinch.active ? "blue" : "gray"

    Component.onCompleted: ImageLoader.createImages()
    
    VisualDataModel
    {
        id: dataModel
        model: ListModel
        {
            id:innerModel
        }
    
        delegate: Image
        {
            width: view.width;
            height: view.height;
            source: url
            fillMode: Image.PreserveAspectFit
        }
    }
    
    // Where can I put this code to zoom the image?
    PinchArea
    {
        property int xpoint
        property int ypoint
        property int pinchscale
        property int pinchrotation
    
        id: pinchy
        enabled: false
        pinch.target: logo
        anchors.fill: parent
        pinch.dragAxis: Pinch.XandYAxis
        pinch.minimumScale: 0.5
        pinch.maximumScale: 2
        pinch.minimumX: 50
        pinch.maximumX: 300
        pinch.minimumY: 50
        pinch.maximumY: 300
        pinch.minimumRotation: -150
        pinch.maximumRotation: 150
    
        onPinchUpdated:
        {
            xpoint = pinch.center.x;
            ypoint = pinch.center.y;
            pinchrotation = pinch.rotation;
            pinchscale = pinch.scale
        }
    }
    
    ListView
    {
        id: view
        anchors.fill: parent;
        model: dataModel
        orientation: ListView.Horizontal
        snapMode: ListView.SnapOneItem;
        flickDeceleration: 0
        highlightFollowsCurrentItem: true
        highlightRangeMode: ListView.StrictlyEnforceRange
        preferredHighlightBegin: 0
        preferredHighlightEnd: 0
        cacheBuffer: width;
        focus: true
        Keys.onLeftPressed:
        {
            if (currentIndex > 0 )
                currentIndex = currentIndex-1;
        }
        Keys.onRightPressed:
        {
            if (currentIndex < count)
                currentIndex = currentIndex+1;
        }
    }
    
    Rectangle
    {
        id: enabler;
        height: 40;
        width: 50;
        radius: 7
        anchors.right: parent.right;
        color: pinchy.enabled ? "green" : "gray"
        Text
        {
            anchors
            {
                left:parent.left
                leftMargin:10
                top: parent.top
                topMargin: 10
            }
            text: pinchy.enabled ? "Disable" : "Enable"
        }
        MouseArea
        {
            anchors.fill: parent;
            onClicked: pinchy.enabled = !pinchy.enabled
        }
    }
    

    }
    @

    @
    // ImageLoader.js
    // I will try to load it another way next time

    function createImages()
    {
    var files = ["image.png","image1.png"];
    var i = 0;
    for (i=0; i<files.length; i++)
    {
    createImage(files[i]);
    }
    }

    function createImage(name)
    {
    innerModel.append({"url": name});
    }
    @

    @
    // main.cpp

    #include <QApplication>
    #include <QtDeclarative>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);

    QDeclarativeView *view = new QDeclarativeView();
    view->setSource(QUrl::fromLocalFile&#40;"./pinch.qml"&#41;&#41;;
    view->show(&#41;;
    
    return app.exec(&#41;;
    

    }
    @

    L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      godbod
      wrote on last edited by
      #2

      The problem was so obvious... Just replace : pinch.target: logo by the appropriate item

      L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

      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