Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to scale to the items of scrollview for qml



  • ApplicationWindow {
    id: mainWindow
    // title: qsTr("AutoResize")
    width: 800
    height: 600
    visible: true
    ScrollView {
    id: control

        width:  parent.width
        height: parent.height
        focus: true
        MouseArea{
            id: dragRegion
            drag.target: control
            drag.axis: "XAxis"
            drag.minimumX: -9999999999999
            drag.minimumY: -9999999999999
            drag.maximumX: 9999999999999 //parentw - inputoutput.width
            drag.maximumY: 9999999999999// parenth - inputoutput.height
            anchors.fill: parent
            property point origin:Qt.point(0,0)
            property point clickPos : "0,0"
            property point lastPos : "0,0"
             onPressed: {
               drag.axis = Drag.XAndYAxis
               origin = Qt.point(mouse.x, mouse.y)
    
              }
              onPositionChanged: {
                   switch (drag.axis) {
                   case Drag.XAndYAxis:
                       var curpos=Qt.point(mouse.x, mouse.y)
                       var deltapos=curpos-lastPos ;
                        control.contentItem.x  += deltapos.y
                        control.contentItem.y+= deltapos.x
                      
                       break
                   }
    
               }
    

    onWheel : {

                                if (wheel.modifiers & Qt.ControlModifier) {
                                      console.log("inputoutput"  )
                                             if (wheel.angleDelta.y > 0)
                                                 control.contentItem.scale += 0.2;
                                             else if (control.contentItem.scale - 0.2 > 0.2)
                                                 control.contentItem.scale -= 0.2;
                                             else
                                               {
                                                  if(control.contentItem.scale>0.05)
                                                    control.contentItem.scale -= 0.01;
                                               }
                                         }
    
                         }
        }
    

    function loadInputOutput(i) {

                       var component = Qt.createComponent("Button.qml");
                       if (component.status == Component.Ready) {
                           var InputOutput = component.createObject(control);
                           InputOutput.parentw=parent.width
                           InputOutput.parenth=parent.height
                           InputOutput.index=i;
                           InputOutput.x=i*(InputOutput.width+20);
                           return (InputOutput.width+20);
                       }
                   }
    
    
               Component.onCompleted:
                {
                   var i=0;
                     var totallength=0;
                   totallength=0;
                   for(  i=0;i<2000;i++)
                         totallength+= loadInputOutput(i);
    
    
                }
    

    }

    i wanna to scale the items within Button.qml but not work



  • anyone has some advice


Log in to reply